PostMessage 中 lParam(低/高键)的工作值是多少? (赢函数)
我已经看到了大约 20 个问题(这里是@stackOverflow),但由于某种原因,我没有得到他们提供的大部分答案。其他人说他们理解,但在我的案例中我没有看到任何工作代码。
我试图将密钥发送到游戏(前台窗口),有点像宏,并且我已经看到了 lParam 中的方式: PostMessage(handle, WM_KEYDOWN , (uint)key, 0); 实际上是有区别的;根据网上的人的说法(他们说,但没有显示代码/示例)。第一次使用 win 函数,所以我有点不知道如何让它在某些游戏中工作;比如说《英雄联盟》或《军团要塞 2》。
我知道这是一个额外的参数,作为解释消息的一种方式发送。但如何让它适用于大多数游戏呢?每个游戏的运作方式都不同吗?
预先感谢,并对我对 win 函数的菜鸟主义表示歉意。
此致,
阿曼多·莱昂
I have seen like 20 questions already (here @ stackOverflow) But for some reason I don't get most of the answers they approach. Some other say they understand but I don't see any piece of working code in my case.
I've trying to send keys to games (foreground window) kinda like a macro, and I've seen how the lParam in: PostMessage(handle, WM_KEYDOWN, (uint)key, 0); actually makes the difference; according to people in the web (they say, but not show code/example). First time employing win functions so I'm kinda lost on how to make it work with some games; let's say "League of Legends", or "Team Fortress 2."
I get it's an extra param sent as a way to interpret the Message. But How do I make it work with most of the games? Does every game work differently?
Thanks in advance, and sorry for my noobie-ism with win functions.
Sincerely,
Armando Leon
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您最好的选择是WM_KEYDOWN 文档。
Your best bet is the documentation for WM_KEYDOWN.
对于按键,您可以在此链接中查看 lParam 包含的内容: http://msdn.microsoft.com/en-us/library/ms646280(v=vs.85).aspx。如果您简单地传递 wParam 和 0 作为 lParam,它可能适用于仅使用虚拟键代码(包含在 wParam 中)的游戏,但不适用于使用扫描代码(在 lParam 中传递)等游戏。
您可以做的是编写一个实用程序,打印出按键的 wParam 和 lParam(以及您希望发送到游戏的任何其他事件(wm_char、wm_keyup 等))。然后你可以使用它来获取你想要的任何组合键的 wParam 和 lParam ,然后如果你将它传递给任何游戏它应该可以工作。传递所有正确的值是确保它在所有情况下都有效的唯一方法。
For key down, you can see what lParam contains at this link: http://msdn.microsoft.com/en-us/library/ms646280(v=vs.85).aspx. If you simply pass wParam and 0 for lParam, it may work for games that only use virtual key code (contained in wParam) but not in games that use, for instance, scan code (passed in lParam).
What you can do is write a utility program that prints out the wParam and lParam for key down (and any other events (wm_char, wm_keyup, etc.) you wish to send to the game). Then you can use it to get wParam and lParam for any key combination you want and then if you pass it to any game it should work. Passing all correct values is only way to make sure it would work in all cases.
您无法使用
PostMessage()
伪造输入。相反,您需要使用SendInput()
。You can't fake input with
PostMessage()
. Instead you need to useSendInput()
.我知道这是一个旧线程,但我不能让别人说“你不能用 PostMessage() 伪造输入”。
当我们搜索“如何更改lparam postmessage”时,该线程会显示在谷歌上。
假设我需要将 Enter 键发送到另一个程序:我将使用 Spy++ 并按物理按键来检查我需要的常量是什么以及我需要的 lParam 值是什么。 (对于常量,您也可以在此处查看 http:// /msdn.microsoft.com/en-us/library/dd375731(v=vs.85).aspx)
检查 keydown,而不是 keyup。
因此,如果我需要带有 cRepeat: 1 Scancode : 29 fExtended : 0 AltDown : 0 fRepeat : 0 fUp: 0 的 Enter 键,
我将不得不更改 lParam 的 32 位,我必须理解这里的数组 http://msdn.microsoft.com/en-us /library/ms646280%28v=vs.85%29.aspx
这些位是这样的:31....3 2 1 0
我需要 1 c重复这样:0000 0000 0000 0001(位0到15,如数组中)
我需要29(十六进制)用于扫描码所以:0010 1001(位16到23)
其余为零
现在我只是重新组合lparam(二进制)我需要:0010 1001 0000 0000 0000 0001
我将其转换为十六进制: 290001
所以现在在我的程序中,如果我使用:
PostMessage(hWnd, WM_KEYDOWN, VK_RETURN, 0x290001);
我希望它能帮助像我一样来到这里的人:)
Seb,
I know it's an old thread but i cant let someone say "You can't fake input with PostMessage()".
This thread is displayed on google when we search for "how to change lparam postmessage".
Let's imagine I need to send an Enter Key to another program: I'll use Spy++ and press physically on the key I need to check what's the constant I need and what are the lParam values I need. (for the constand you can check here too http://msdn.microsoft.com/en-us/library/dd375731(v=vs.85).aspx)
Check the keydown, not the keyup.
So if I need an Enter Key with cRepeat: 1 Scancode : 29 fExtended : 0 AltDown : 0 fRepeat : 0 fUp: 0 ,
I'll have to change the 32 bits of the lParam, I have to understand the array here http://msdn.microsoft.com/en-us/library/ms646280%28v=vs.85%29.aspx
the bits are like that : 31....3 2 1 0
I need 1 for cRepeat so : 0000 0000 0000 0001 (bits 0 to 15 like in the array)
I need 29 (in hexa) for Scancode so : 0010 1001 (bits 16 to 23)
the rest is at zero
Now i just regroup the lparam (in binary) I need : 0010 1001 0000 0000 0000 0001
And I convert it to hexadecimal : 290001
So now in my program it's going to work if I use :
PostMessage(hWnd, WM_KEYDOWN, VK_RETURN, 0x290001);
I hope it'll help people who come here like I did :)
Seb,