If I send a WM_KEYDOWN message (using wndproc) will the computer hold the key down until I send WM_KEYUP?

我与影子孤独终老i 提交于 2020-01-03 02:53:11

问题


I am looking for a solution to programmatically hold a keyboard key down during some time (I don't know how many time).

I think that if I send a WM_KEYDOWN message the key will be held down until WM_KEYUP is send, but I am not sure.

I would test it. But I need to go and I don't have much time. I want to see if someone already tested this.

Here is an other question I posted, related to this one.
I want to make a virtual keyboard. Do I need to send WM_KEYDOWN to the current active window or HWND_BROADCAST?


回答1:


No, because If you examine the messages sent when using the keyboard, you'll see that the message are as follow:

WM_KEYDOWN
WM_KEYPRESS
WM_KEYUP

The WM_KEYPRESS message is sent every couple of ticks (depending on the keyboard configuration).




回答2:


WM_KEYDOWN and WM_KEYUP are messages generated by the system - it's dependent on how the application interprets those messages. Synthesizing these messages will have no effect on the actual keyboard state.

If you want to simulate keyboard input, use the SendInput API.



来源:https://stackoverflow.com/questions/2089968/if-i-send-a-wm-keydown-message-using-wndproc-will-the-computer-hold-the-key-do

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!