PostMessage发送组合键,我实验过几次,都失败
比如下面这些语句发送ALT+V, 根本无法发送成功
PostMessage(hWnd,WM_SYSKEYDOWN,VK_MENU,0); PostMessage(hWnd,WM_SYSKEYDOWN,VK_V,0); Sleep(50); PostMessage(hWnd,WM_SYSKEYUP,VK_V,0); PostMessage(hWnd,WM_SYSKEYUP,VK_MENU,0);
后来我使用了spy++, 提出消息列表里捕获到的消息, 用PostMessage发送.这种方式是可行的, ALT+V
PostMessage(hWnd,WM_SYSKEYDOWN, VK_MENU, 0x20380001); PostMessage(hWnd,WM_SYSKEYDOWN, 0x56,0x20200001); PostMessage(hWnd,WM_SYSCHAR,0x76,0x20200001); PostMessage(hWnd,WM_SYSKEYUP,0x56,0xE0200001); PostMessage(hWnd,WM_KEYUP, VK_MENU, 0xC0380001);
如果是只发送ALT的组合键,还有一种方式是
PostMessage(hWnd,WM_SYSKEYDOWN,VK_V,1<<29);
然后还有一种方式就是使用keybd_event的帮助, 使用keybd_event按着控制键,再用PostMessage发送按键的字母, 比如发送CTRL+L,
如果要发送shift键, 将VK_CONTROL替换成shift就行了.
keybd_event(VK_CONTROL, 0, 0, 0); PostMessage(hWnd, WM_KEYDOWN, VK_L, 0x001E0001); PostMessage(hWnd, WM_KEYUP, VK_L, 0xC01E0001); keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);
这是我最近几天写按键程序的一点总结, 希望能帮助到其他的朋友.
时间: 2024-10-11 23:43:16