INPUT
構造をSendInput()
使用し、フックを使用して入力コマンドを別のウィンドウに送信するプロジェクトに取り組んでいます。
次のコードを使用して、最後にアクセスしたアプリケーション ウィンドウのハンドルを取得しています。
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
次に、貼り付けコマンドを送信します。
// 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 ) );
今の問題は、これで作業できることですWin 7, 8 and 8.1
。しかし、コマンドを送信する前にXP
、プログラムの最初のブロックが余分に押されているという問題が発生しています。TAB
CTRL-V
なぜこれが起こっているのか誰にでも教えてもらえますか? どうすればこれを解決できますか?いつでも提案をいただければ幸いです。前もって感謝します。