如何在 C++ 中模拟按键操作
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5607849/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to simulate a key press in C++
提问by llk
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!
我想知道如何在 C++ 中模拟一个关键的抑郁症。例如,当我运行程序时,它按下字母“W”键的代码。我不想在控制台窗口中显示它,我只想在每次单击文本字段时显示“W”键。谢谢!
Note: I am not trying to make a spammer.
注意:我不是要制造垃圾邮件发送者。
采纳答案by Greg Hewgill
It looks like you want to use either SendInput()
or keybd_event()
(which is an older way of doing the same thing).
看起来您想使用SendInput()
or keybd_event()
(这是做同样事情的一种较旧的方式)。