问题描述
我正在一个项目中使用 SendInput()
将粘贴命令发送到另一个应用程序窗口,如下所示:
I am working on one project where I am sending Paste command to another application window using SendInput()
As Follows:
`INPUT input, vButton, ctrl1, ctrl2;`
input.type = INPUT_KEYBOARD;
input.ki.wVk = VK_CONTROL;
input.ki.wScan = 0;
input.ki.dwFlags = KEYEVENTF_UNICODE ;
input.ki.time = 0;
input.ki.dwExtraInfo = 0;
vButton .type = INPUT_KEYBOARD;
vButton .ki.wVk = 0x56;
vButton .ki.wScan =0;
vButton .ki.dwFlags = KEYEVENTF_UNICODE ;
vButton .ki.time = 0;
vButton .ki.dwExtraInfo = 0;
ctrl1.type = INPUT_KEYBOARD;
ctrl1.ki.wVk = VK_CONTROL;
ctrl1.ki.wScan = 0;
ctrl1.ki.dwFlags = KEYEVENTF_KEYUP |KEYEVENTF_UNICODE ;
ctrl1.ki.time = 0;
ctrl1.ki.dwExtraInfo = 0;
ctrl2.type = INPUT_KEYBOARD;
ctrl2.ki.wVk = VK_TAB;
ctrl2.ki.wScan = 0;
ctrl2.ki.dwFlags = KEYEVENTF_KEYUP ;
ctrl2.ki.time = 0;
ctrl2.ki.dwExtraInfo = 0;
// Send Input To Another Window
::ShowWindow(mainHwnd, SW_SHOWNORMAL);
int retval = SendInput(1, &input, sizeof(INPUT));
retval = SendInput(1, &vButton, sizeof(INPUT));
retval = SendInput(1, &ctrl1, sizeof(INPUT));
retval = SendInput(1, &ctrl2, sizeof(INPUT));`
除了具有 VK_TAB
键的 INPUT
之外,它工作正常.我想向应用程序发送 VK_TAB
命令.
It is working fine except INPUT
having VK_TAB
key. I want Send VK_TAB
command to the application.
但它没有按预期工作,即即使在 SendInput()
成功完成后,下一个控件也没有获得焦点.
But it is not Working as Expected i.e. The next control is not getting focused even after successful completion of the SendInput()
.
谁能帮我解决这个问题.我如何才能专注于其他应用程序的下一个控制?
Can anyone help me on this.How I can focus on next control of other application?
提前致谢.
推荐答案
如果您只是发送简单的密钥,请不要将 KEYEVENTF_UNICODE
用于 dwFlags
.将 dwFlags
设置为 0 用于 KeyDown 转换,并将其设置为 KEYEVENTF_KEYUP
用于 KeyUp 转换.
Don't use KEYEVENTF_UNICODE
for dwFlags
if you are just sending simple keys. Set dwFlags
to 0 for the KeyDown transition, and set it to KEYEVENTF_KEYUP
for the KeyUp transition.
您忘记了 SendInput
V
的 KeyUp 转换和 VK_TAB
的 KeyDown 转换
You forgot to SendInput
a KeyUp transition for V
and a KeyDown transition for VK_TAB
使用那种代码.
INPUT input:
input.type = INPUT_KEYBOARD;
input.ki.time = 0;
input.ki.dwExtraInfo = 0;
input.ki.wScan = 0;
input.ki.dwFlags = 0;
// Ctrl Down
input.ki.wVk = VK_CONTROL;
SendInput( 1, &input, sizeof( INPUT ) );
// V Down
input.ki.wVk = 0x56;
SendInput( 1, &input, sizeof( INPUT ) );
// V Up
input.ki.dwFlags = KEYEVENTF_KEYUP;
SendInput( 1, &input, sizeof( INPUT ) );
// Ctrl Up
input.ki.wVk = VK_CONTROL;
SendInput( 1, &input, sizeof( INPUT ) );
// Tab Down
input.ki.wVk = VK_TAB;
input.ki.dwFlags = 0;
SendInput( 1, &input, sizeof( INPUT ) );
// Tab Up
input.ki.dwFlags = KEYEVENTF_KEYUP;
SendInput( 1, &input, sizeof( INPUT ) );
这篇关于VK_TAB 在我的 C++ 程序中的 SendInput() 中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!