1

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));` 

It is working fine except INPUT having VK_TAB key. I want Send VK_TAB command to the application.

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?

Thank You in Advance.

1
  • You set focus to a different control on a dialog by sending a WM_NEXTDLGCTL message. Commented Dec 31, 2013 at 11:46

1 Answer 1

4

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.

You forgot to SendInput a KeyUp transition for V and a KeyDown transition for VK_TAB

Use that kind of code.

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 ) ); 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.