以与键盘相同的方式发送按键?
我正在尝试为我玩的游戏编写一个小应用程序,该应用程序允许我向其发送按键信息。不幸的是,他们的软件会阻止来自 SendMessage/PostMessage 和 SendKeys 的传入按键事件。通常我只会说这是故意的,但不管怎样......
我的 G15 键盘允许您为游戏创建键绑定宏,并且可以很好地工作。由于宏是从键盘软件运行的,因此它们使用的是我已经尝试过的其他形式的发送按键。
他们是一种较低级别的按键方式,还是基本上以与按下按键相同的方式发送按键?这是迄今为止我的代码尝试...
private void button1_Click(object sender, EventArgs e)
{
// TRY #1
IntPtr hWnd = FindWindow("NIVAL_MMO_ENGINE", "Allods Online");
PostMessage(hWnd, WM_KEYDOWN, ((IntPtr)Keys.W), IntPtr.Zero);
// TRY #2
IntPtr Handle = FindWindow("NIVAL_MMO_ENGINE", "Allods Online");
// Verify that Process is a running process.
if (Handle == IntPtr.Zero)
{
MessageBox.Show("Calculator is not running.");
return;
}
SetForegroundWindow(Handle);
SendKeys.SendWait("w");
}
I am trying to write a small application for a game I play that allows me to send key presses to it. Unfortunately their software blocks incoming key press events from both SendMessage/PostMessage and SendKeys. Normally I would just say that is intentional and leave it be however...
My G15 Keyboard allows you to create key-binded macros for games, and works fine with this. Since the macros are ran from the keyboard software, they are using some other form of sending key presses than what I have already tried.
Is their a lower level way of doing key presses, or basically sending them in the same manner as if the had been pushed? Here is my code attempts thus far...
private void button1_Click(object sender, EventArgs e)
{
// TRY #1
IntPtr hWnd = FindWindow("NIVAL_MMO_ENGINE", "Allods Online");
PostMessage(hWnd, WM_KEYDOWN, ((IntPtr)Keys.W), IntPtr.Zero);
// TRY #2
IntPtr Handle = FindWindow("NIVAL_MMO_ENGINE", "Allods Online");
// Verify that Process is a running process.
if (Handle == IntPtr.Zero)
{
MessageBox.Show("Calculator is not running.");
return;
}
SetForegroundWindow(Handle);
SendKeys.SendWait("w");
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
要使用PostMessage函数发送密钥,需要这样定义参数:
您可以在Spy++中找到参数,
享受!!
To send a key using the function PostMessage, need to define the parameters like this:
you can find parameters in Spy++,
Enjoy!!
将密钥放入输入队列的最低级别方法是 发送输入。如果这不起作用,那么游戏正在使用输入堆栈做一些有趣的事情。
G15 键盘完全有可能支持“硬件”宏 - 即键盘本身正在生成一系列按键向上/向下事件。
The lowest level way to put keys into the input queue is SendInput. If that doesn't work, then the game is doing some interesting things with the input stack.
It's entirely possible that the G15 keyboard supports "hardware" macros - i.e., the keyboard itself is generating a series of key up/down events.