使用哪个 WM_Message?
我正在为一款不是我制作的游戏开发客户端加载程序。我已经构建了一个鼠标和按键事件库以发送给客户端,并且它们在大部分情况下都可以工作。然而,有一点我似乎无法弄清楚。
我将代码的输入部分设置为:
[DllImport("user32.dll")]
public static extern IntPtr PostMessage(IntPtr hWnd, uint Msg, uint wParam, uint lParam);
//Send each character of string one at a time
foreach(Char c in Input)
PostMessage(mainwnd, (uint)WM.CHAR, c, 1);
//Send final enter key to send message in game
PostMessage(mainwnd, (uint)WM.CHAR, 0x0D, 1);
这工作正常,但有两件事它没有考虑到。
- 在游戏中,您需要在键入内容之前按 Enter 键才能打开聊天
- 有热键可以打开菜单
我尝试过诸如 PostMessage(mainwnd, (uint)WM.CHAR, 0x0D, 1);
发送开始回车键,但游戏不处理它。如果我使用 PostMessage 尝试打开菜单,也会发生同样的情况。除非聊天窗口在发送消息之前已打开,否则不会解析任何内容。
我认为我使用了错误的 WM_Message,但我找不到我需要的那个。我已经尝试过:
- WM_CHAR
- WM_SYSCHAR
- WM_MENUCHAR
- WM_HOTKEY
- WM_APPCOMMAND
- WM_KEYDOWN 后跟 WM_KEYUP
也许还有其他一些,但没有运气。有谁知道哪个命令可能有效?
I am working on a client loader for a game not made by me. I've built a library of mouse and key events to send to the client and they work for the most part. However, there is one bit I cannot seem to figure out.
I made the typing portion of my code this:
[DllImport("user32.dll")]
public static extern IntPtr PostMessage(IntPtr hWnd, uint Msg, uint wParam, uint lParam);
//Send each character of string one at a time
foreach(Char c in Input)
PostMessage(mainwnd, (uint)WM.CHAR, c, 1);
//Send final enter key to send message in game
PostMessage(mainwnd, (uint)WM.CHAR, 0x0D, 1);
This works fine, but there are two things it doesn't account for.
- In-Game you are required to press the enter key before typing to open chat
- There are hotkeys to open menus
I have tried things like PostMessage(mainwnd, (uint)WM.CHAR, 0x0D, 1);
to send the beginning enter key, but the game doesn't process it. Same thing happens if I use PostMessage to try to open menus. Nothing is parsed unless the chat window is already open before sending the message.
I figure I am using the wrong WM_Message, but I cannot find which one I need. I have tried:
- WM_CHAR
- WM_SYSCHAR
- WM_MENUCHAR
- WM_HOTKEY
- WM_APPCOMMAND
- WM_KEYDOWN followed by WM_KEYUP
And maybe a few others, but no luck. Does anyone know which command might work?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你必须很幸运才能做到这一点。键盘输入不仅仅是一条消息。它还会影响(除其他外)
GetKeyboardState
和GetAsyncKeyState
< /a> ——用这些来模拟输入是很重要的。如果键盘焦点在其他地方,就会把事情搞砸。您可以尝试发布
WM_KEYDOWN
和WM_KEYUP
< /a> 生成稍低级别的消息。较低级别仍然是
SendInput
模拟来自键盘驱动程序的输入。键盘焦点必须位于正确的位置,否则会将输入发送到错误的窗口。You will have to get lucky for this to work. Keyboard input is not merely a message. It also affects (among others)
GetKeyboardState
andGetAsyncKeyState
-- and simulating input with these is non-trivial. And if keyboard focus is elsewhere, it can screw things up.You can try posting
WM_KEYDOWN
andWM_KEYUP
to generate a slightly lower-level message.Lower-level still is
SendInput
which simulates input from the keyboard driver. Keyboard focus must be in the right place or it will send the input to the wrong window.尝试使用 WM_KEYDOWN,然后使用 WM_KEYUP。使用 VK_ENTER 代码(我认为)。
Try WM_KEYDOWN, followed by WM_KEYUP. With the VK_ENTER code (I think).