Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
为什么我在使用 GetAsyncKeyState 时一次按下会获得 1 个(几百个)以上的按键。当我按下一次时,它会打印一百个相同的键。谢谢,
GetAsyncKeyState告诉你键盘的状态,一个键是否向下/向上,而不是自上次通话后是否被按下。如果你在一个循环中调用它,只要你按住键,你就会得到“key is down”——而且这个循环的执行速度比你移动手指的速度要快得多。
GetAsyncKeyState
如果您想要键盘事件句柄WM_KEYDOWN和WM_KEYUP.
WM_KEYDOWN
WM_KEYUP
如果你想要一个全局热键,使用RegisterHotKey
RegisterHotKey