使用哪个 WM_Message?

发布于 2024-12-23 03:23:47 字数 951 浏览 3 评论 0原文

我正在为一款不是我制作的游戏开发客户端加载程序。我已经构建了一个鼠标和按键事件库以发送给客户端,并且它们在大部分情况下都可以工作。然而,有一点我似乎无法弄清楚。

我将代码的输入部分设置为:

[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);

这工作正常,但有两件事它没有考虑到。

  1. 在游戏中,您需要在键入内容之前按 Enter 键才能打开聊天
  2. 有热键可以打开菜单

我尝试过诸如 PostMessage(mainwnd, (uint)WM.CHAR, 0x0D, 1);发送开始回车键,但游戏不处理它。如果我使用 PostMessage 尝试打开菜单,也会发生同样的情况。除非聊天窗口在发送消息之前已打开,否则不会解析任何内容。

我认为我使用了错误的 WM_Message,但我找不到我需要的那个。我已经尝试过:

  1. WM_CHAR
  2. WM_SYSCHAR
  3. WM_MENUCHAR
  4. WM_HOTKEY
  5. WM_APPCOMMAND
  6. 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.

  1. In-Game you are required to press the enter key before typing to open chat
  2. 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:

  1. WM_CHAR
  2. WM_SYSCHAR
  3. WM_MENUCHAR
  4. WM_HOTKEY
  5. WM_APPCOMMAND
  6. WM_KEYDOWN followed by WM_KEYUP

And maybe a few others, but no luck. Does anyone know which command might work?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

渔村楼浪 2024-12-30 03:23:47

你必须很幸运才能做到这一点。键盘输入不仅仅是一条消息。它还会影响(除其他外) GetKeyboardStateGetAsyncKeyState< /a> ——用这些来模拟输入是很重要的。如果键盘焦点在其他地方,就会把事情搞砸。

您可以尝试发布 WM_KEYDOWNWM_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 and GetAsyncKeyState -- 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 and WM_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.

欲拥i 2024-12-30 03:23:47

尝试使用 WM_KEYDOWN,然后使用 WM_KEYUP。使用 VK_ENTER 代码(我认为)。

Try WM_KEYDOWN, followed by WM_KEYUP. With the VK_ENTER code (I think).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文