I am working on one project where I am using INPUT
structure and SendInput()
to send Input command to another window using Hook.
I am using following code to get the handle of the last visited Application Window.
INPUT input;
input.type = INPUT_KEYBOARD;
input.ki.time = 0;
input.ki.dwExtraInfo = 0;
input.ki.wScan = 0;
input.ki.dwFlags = 0;
// Trial
// ALT Key Down
input.ki.wVk = VK_MENU;
SendInput( 1, &input, sizeof( INPUT ) );
// Tab Key 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 ) );
// ALT Key Up
input.ki.wVk = VK_MENU;
SendInput( 1, &input, sizeof( INPUT ) );
// ALT Up
input.ki.dwFlags = KEYEVENTF_KEYUP;
SendInput( 1, &input, sizeof( INPUT ) );
// Give Sleep Time
Sleep(500);
// ALT Key Down
input.ki.wVk = VK_MENU;
SendInput( 1, &input, sizeof( INPUT ) );
// Tab Key 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 ) );
// ALT Key Up
input.ki.wVk = VK_MENU;
SendInput( 1, &input, sizeof( INPUT ) );
// ALT Key Up
input.ki.dwFlags = KEYEVENTF_KEYUP;
SendInput( 1, &input, sizeof( INPUT ) );
// Get Last Window Handle from the Hook Dll
and Then Send Paste Command:
// Send Paste Command To Previous Window
// Ctrl Down
input.ki.wVk = VK_CONTROL;
input.ki.dwFlags = 0;
::ShowWindow(mainHwnd, SW_SHOW);
SendInput( 1, &input, sizeof( INPUT ) );
// V Down
input.ki.wVk = 0x56;
::ShowWindow(mainHwnd, SW_SHOW);
SendInput( 1, &input, sizeof( INPUT ) );
// V Up
input.ki.dwFlags = KEYEVENTF_KEYUP;
::ShowWindow(mainHwnd, SW_SHOW);
SendInput( 1, &input, sizeof( INPUT ) );
// Ctrl Up
input.ki.wVk = VK_CONTROL;
::ShowWindow(mainHwnd, SW_SHOW);
SendInput( 1, &input, sizeof( INPUT ) );
// Tab Down
input.ki.wVk = VK_TAB;
input.ki.dwFlags = 0;
::ShowWindow(mainHwnd, SW_SHOW);
SendInput( 1, &input, sizeof( INPUT ) );
// Tab Up
input.ki.dwFlags = KEYEVENTF_KEYUP;
::ShowWindow(mainHwnd, SW_SHOW);
SendInput( 1, &input, sizeof( INPUT ) );
Now the problem is I am able to work with this on Win 7, 8 and 8.1
. but I am getting problem on XP
that the first block of program is pressing extra TAB
before sending CTRL-V
Command.
Can Any one tell me Why this is happening? And How can I solve this? Any time of Suggestions will be appreciated. Thanks in advance.