GetAsyncKeyState “strange” behavior

前端 未结 1 994
说谎
说谎 2020-12-22 02:43

I have 2 simple forms, Form1 and Form2 (Delphi 7). Form1 opens Form2, and there I wait for a specific key combination (Ctrl + F2). Once I close Form2 and back to Form1, I ne

相关标签:
1条回答
  • 2020-12-22 03:30

    Your test is wrong. From the documentation:

    If the function succeeds, the return value specifies whether the key was pressed since the last call to GetAsyncKeyState, and whether the key is currently up or down. If the most significant bit is set, the key is down, and if the least significant bit is set, the key was pressed after the previous call to GetAsyncKeyState.

    To test just for the key being down, look at the most significant bit being set. That is, if the value is negative:

    if GetAsyncKeyState(VK_Control) < 0 then
    

    I would also suggest that you should be calling GetKeyState instead, to get the state when the button is pressed rather than GetAsyncKeyState which is the state later when you process the message.

    0 讨论(0)
提交回复
热议问题