How to simulate a key press in C++

2019-01-13 18:45发布

I was wondering how can I simulate a key depression in C++. Such as having code that when I run the program it presses the letter "W" key. I don't want to be displaying it in a console window I just want it to display the "W" key every time I click on a text field. Thanks!

Note: I am not trying to make a spammer.

2条回答
放我归山
2楼-- · 2019-01-13 19:08

How can I fire a key press or mouse click event without touching any input device at system level?

Oh, by the way, you probably don't want to do this stuff; if you are simulating key-presses to make your application behave the way you want it to, then you might want to rethink how you are designing your application. In my experience sending key presses and intercepting them causes nothing but woes.

查看更多
小情绪 Triste *
3楼-- · 2019-01-13 19:12

It looks like you want to use either SendInput() or keybd_event() (which is an older way of doing the same thing).

查看更多
登录 后发表回答