如何将键盘输入发送到 OpenGL/DirectX 游戏窗口? [英] How can I send keyboard input to a OpenGL/DirectX game window?

查看:24
本文介绍了如何将键盘输入发送到 OpenGL/DirectX 游戏窗口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在游戏窗口中模拟按键(使用 Windows 中的任何编程语言)?

How can I simulate a keypress in a game window (using any programming language in Windows)?

AutoHotKeys 脚本和 .NET SendKeys 函数不起作用...

AutoHotKeys Scripts and .NET SendKeys functions do not work...

推荐答案

使用 AutoIt!3(与 AutoHotKeys 非常相似),您将使用 Send() (http://www.autoitscript.com/autoit3/docs/functions/Send.htm),但请确保在此之前激活游戏窗口 (WinActivate()).

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.

我已经成功地使用它与第二人生(使用 OpenGL)交互.您可能需要在模拟按键之间使用 Sleep() 时间段,因为并非所有游戏都实现了良好的键盘缓冲区.

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.

如果游戏是异步轮询,您需要使用 downup 修饰符标志:

If the game is polling asynchonously, you want to use the down and up modifiers flags:

Send("{left down}")  ; hold down the LEFT key
Sleep(10)            ; keep it pressed for 10 milliseconds
Send("{left up}")    ; release the LEFT key

确定按键保持多长时间完全取决于您试图控制的程序轮询键盘的频率;无法确定.

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.

这篇关于如何将键盘输入发送到 OpenGL/DirectX 游戏窗口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆