我使用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,然后我找到了" dwFlags [in]" keybd_event函数的参数。 当我运行代码时,键组合起作用如下:
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);
答案 0 :(得分: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);
答案 1 :(得分:0)
同时向下移动VK_LSHIFT和VK_RSHIFT,然后同时向VK_END和SHIFT上移 左右同时对我有用