如何在Windows中模拟SHIFT + END组合键

我使用keybd_event函数来模拟SHIFT + END组合键,但它不起作用:

keybd_event(VK_SHIFT,0,0,0); keybd_event(VK_END,0,0,0); keybd_event(VK_END,0,KEYEVENTF_KEYUP,0); keybd_event(VK_SHIFT,0,KEYEVENTF_KEYUP,0); 

脱字符移动到行的末尾,但不要select文本(突出显示)。 就像input一个END键一样。 有人可以帮忙吗? 非常感谢〜


我已经解决了这个问题! 我使用spy ++来查找当我使用键盘发送Shift + End键时发生了什么,并且我得到了这些消息:

 WM_KEYDOWN nVirtKey:VK_SHIFT cRepeat:1 ScanCode:2A fExtended:0 fAltDown:0 fRepeat:0 fUp:0 WM_KEYDOWN nVirtKey:VK_END cRepeat:1 ScanCode:4F fExtended:1 fAltDown:0 fRepeat:0 fUp:0 WM_KEYUP nVirtKey:VK_END cRepeat:1 ScanCode:4F fExtended:1 fAltDown:0 fRepeat:1 fUp:1 WM_KEYUP nVirtKey:VK_SHIFT cRepeat:1 ScanCode:2A fExtended:0 fAltDown:0 fRepeat:1 fUp:1 

当我运行上面的代码,我得到这些消息:

 WM_KEYDOWN nVirtKey:VK_SHIFT cRepeat:1 ScanCode:0 fExtended:0 fAltDown:0 fRepeat:0 fUp:0 WM_KEYUP nVirtKey:VK_SHIFT cRepeat:1 ScanCode:0 fExtended:0 fAltDown:0 fRepeat:1 fUp:1 WM_KEYDOWN nVirtKey:VK_END cRepeat:1 ScanCode:0 fExtended:1 fAltDown:0 fRepeat:0 fUp:0 WM_KEYUP nVirtKey:VK_END cRepeat:1 ScanCode:0 fExtended:1 fAltDown:0 fRepeat:1 fUp:1 WM_KEYDOWN nVirtKey:VK_SHIFT cRepeat:1 ScanCode:0 fExtended:0 fAltDown:0 fRepeat:0 fUp:0 WM_KEYUP nVirtKey:VK_SHIFT cRepeat:1 ScanCode:0 fExtended:0 fAltDown:0 fRepeat:1 fUp:1 

窗口在VK_END的WM_KEYDOWN消息之前获得VK_SHIFT的WM_KEYUP消息。 消息之间的差异是“fExtended”的值。 当我使用键盘时,END键的fExtended值为1,当我运行代码时,值为0.所以我尝试将fExtended值设置为1,并且我发现keybd_event函数的“dwFlags [in]”参数。 当我运行代码时,键组合的作用如下:

 keybd_event(VK_SHIFT,0x2A,0,0); keybd_event(VK_END,0x4F,KEYEVENTF_EXTENDEDKEY | 0,0); keybd_event(VK_END,0x4F,KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP,0); keybd_event(VK_SHIFT,0x2A,KEYEVENTF_KEYUP,0); 

 UINT m_scanShift = MapVirtualKey(VK_SHIFT, 0); UINT m_scanEnd = MapVirtualKey(VK_END, 0); keybd_event(VK_SHIFT, m_scanShift, 0, 0); Sleep(10); keybd_event(VK_END, m_scanEnd, 0, 0); Sleep(10); keybd_event(VK_END, m_scanEnd, KEYEVENTF_KEYUP, 0); Sleep(10); keybd_event(VK_SHIFT, m_scanShift, KEYEVENTF_KEYUP, 0);