防止winapi累积按键

时间:2015-12-08 18:42:23

标签: winapi assembly

我正在用汇编语言编写一个WinApi,程序对keypress做出反应,问题是,如果例程没有完成并且同时按下键,它会开始累积,这意味着一旦例程完成,它就会考虑到用户在例程正在进行时按下键的次数。 经典消息循环:

.MessageLoop:
  invoke PeekMessage,Message,NULL,0,0,PM_REMOVE       
  test eax,eax                                        
  jz near .NoMess                                 

  cmp dword [Message + MSG.message],WM_QUIT         
  jz near .Finish                                     

  invoke TranslateMessage,Message                   
  invoke DispatchMessage,Message                     
  .NoMess:
 ; some code
jmp .MessageLoop

处理邮件:

function WndProc,hWnd,wMsg,wParam,lParam
begin
 mov eax,dword [wMsg]          

  cmp eax,WM_DESTROY             
  je near .Destroy

  cmp eax,WM_CLOSE              
  je near .Destroy              

  cmp eax, WM_KEYDOWN                  
  je near .keyDown ; when key is pressed, then it is checked what key it is, meanwhile I need program to ignore all keypressed

  cmp eax, WM_PAINT
  je near .Paint

  invoke DefWindowProc,[hWnd],[wMsg],[wParam],[lParam]
  return eax 

让我说我有例程处理W按钮,在例程的过程中我希望忽略所有其他W键。

0 个答案:

没有答案