我使用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);

插入符号移动到行的末尾,但不要选择文本(突出显示)。就像输入一个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);

08-26 19:51