0

我正在开发一个使用INPUT结构的项目,并SendInput()使用 Hook 将输入命令发送到另一个窗口。

我正在使用以下代码来获取上次访问的应用程序窗口的句柄。

            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是额外的。TABCTRL-V

谁能告诉我为什么会这样?我该如何解决这个问题?任何时间的建议将不胜感激。提前致谢。

4

0 回答 0