如何将键盘输入发送到 OpenGL/DirectX 游戏窗口?
如何在游戏窗口中模拟按键(使用 Windows 中的任何编程语言)?
AutoHotKeys 脚本和 .NET SendKeys 功能不起作用...
How can I simulate a keypress in a game window (using any programming language in Windows)?
AutoHotKeys Scripts and .NET SendKeys functions do not work...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用 AutoIt!3(与 AutoHotKeys 非常相似),您可以使用
Send()
(http://www.autoitscript.com/autoit3/docs/functions/Send.htm),但请确保游戏窗口处于活动状态(WinActivate()
) 之前。我已经使用它成功地与《第二人生》(使用 OpenGL)进行交互。您可能需要在模拟按键之间有一个
Sleep()
时间段,因为并非所有游戏都实现良好的键盘缓冲区。如果这不起作用,则游戏可能会直接访问硬件驱动程序,而您唯一的选择就是连接到键盘驱动程序。
如果游戏是异步轮询,您需要使用
down
和up
修饰符标志:计算出按住按键的时间完全取决于您执行程序的频率正在尝试控制正在轮询键盘;没有办法确定。
Using AutoIt!3 (which is quite similar to AutoHotKeys), you'd use
Send()
(http://www.autoitscript.com/autoit3/docs/functions/Send.htm), but make sure to have the game window active (WinActivate()
) before you do.I've used this to interact with Second Life (which uses OpenGL) succesfully. You may require a
Sleep()
period between simulated key presses, since not all games implement good keyboard buffers.If this doesn't work, the game is probably accessing the hardware drivers directly, and your only option is to hook into the keyboard drivers.
If the game is polling asynchonously, you want to use the
down
andup
modifiers flags:Figuring out how long to keep the key pressed depends entirely on how frequently the program you're trying to control is polling the keyboard; no way to know for sure.
有什么编程语言吗?我的建议是用 C 或 C++ 编写一个小应用程序(尽管您也可以在 .NET 应用程序中使用 P/Invoke< /a>)。
具体来说,您正在寻找
SendInput
来自 Win32 API 的函数,它可以将低级键盘和鼠标输入发送到应用程序。它通过INPUT
来执行此操作包含您要发送的信息的结构。当然,此函数的使用受 UIPI 的约束,这意味着您要注入输入的应用程序必须以与进行注入的应用程序相同或更低的完整性级别运行。
然而,由于这个函数通常是
SendKeys
在幕后使用的,所以最后一个小警告可能就是它不起作用的原因。很难准确地说;你没有告诉我们你所说的“不工作”是什么意思。Any programming language? My recommendation is to write up a little app in C or C++ (although you could also do this in a .NET app with P/Invoke).
Specifically, you're looking for the
SendInput
function from the Win32 API, which can send low-level keyboard and mouse input to an application. It does this in terms of anINPUT
structure that contains the information you want to send.Of course, use of this function is subject to UIPI, which means that the application you're injecting input into must be running at an equal or lesser integrity level than the application that is doing the injecting.
However, since this function is generally what
SendKeys
uses under the covers, that last little caveat might be why it isn't working. It's hard to say exactly; you don't tell us what you mean by "do not work".