慕姐8265434
The KEYBDINPUT structure contains information about a simulatedkeyboard event. Syntax typedef struct tagKEYBDINPUT {WORD wVk;WORD wScan;DWORD dwFlags;DWORD time;ULONG_PTR dwExtraInfo;} KEYBDINPUT, *PKEYBDINPUT; Members wVk Specifies a virtual-key code. The code must be a value in the range 1 to254. The Winuser.h header file provides macro definitions (VK_*) for each value.If the dwFlags memberspecifies KEYEVENTF_UNICODE, wVk must be 0. wScan Specifies a hardware scan code for the key. If dwFlags specifies KEYEVENTF_UNICODE, wScan specifies a Unicode characterwhich is to be sent to the foreground application. dwFlags Specifies various aspects of a keystroke. This member can be certaincombinations of the following values. KEYEVENTF_EXTENDEDKEY If specified, the scan code was preceded by a prefix byte that has the value0xE0 (224). KEYEVENTF_KEYUP If specified, the key is being released. If not specified, the key is beingpressed. KEYEVENTF_SCANCODE If specified, wScanidentifies the key and wVkis ignored. KEYEVENTF_UNICODE Windows 2000/XP: If specified, the system synthesizes a VK_PACKETkeystroke. The wVk parametermust be zero. This flag can only be combined with the KEYEVENTF_KEYUP flag. Formore information, see the Remarks section. time Time stamp for the event, in milliseconds. If this parameter is zero, thesystem will provide its own time stamp. dwExtraInfo Specifies an additional value associated with the keystroke. Use the GetMessageExtraInfo function to obtain this information.函数说明如上:INPUT input[2];memset(input, 0, sizeof(input));//设置模拟键盘输入input[0].type =input[1].type= INPUT_KEYBOARD;input[0].ki.wVk= VK_TAB;input[0].ki.dwFlags=0;//先按下// 释放按键input[1].ki.dwFlags = KEYEVENTF_KEYUP;//放开input[1].ki.wVk=VK_TAB;SendInput(1, input, sizeof(INPUT));Sleep(2000);SendInput(1, input+1, sizeof(INPUT));没试过,你试试。
繁星淼淼
class SKeyboardInput { // KEYBDINPUT private: INPUT m_keyboard ; public: SKeyboardInput( int iScanCode, bool bDown = TRUE, int iTime = 0 ):m_keyboard() { m_keyboard.type = INPUT_KEYBOARD ; m_keyboard.ki.wScan = iScanCode ; m_keyboard.ki.dwFlags = KEYEVENTF_SCANCODE | (bDown ? 0 : KEYEVENTF_KEYUP) ; m_keyboard.ki.time = iTime ; m_keyboard.ki.dwExtraInfo = 0 ; } public: DWORD scan() const { return m_keyboard.ki.wScan ; } DWORD time() const { return m_keyboard.ki.time ; } public: int Send( ) const { if( m_keyboard.ki.time ) Sleep( m_keyboard.ki.time ) ; SendInput( 1, const_cast<LPINPUT>( &m_keyboard ), sizeof(INPUT) ) ; return 0 ; } } ;摘自我以前写的一个程序片段用类稍微的封装了下,用法:SKeyboardInput input( 15, TRUE, 100 ) ; // 扫描码 = 15(tab) 按下, 延时100SKeyboardInput input2( 15, FALSE, 200 ) ; // 扫描码 = 15(tab) 松开, 延时200input.Send() ;input2.Send()这里使用的是扫描码, 你可以用MapVirtualKey()来进行 扫描 虚拟码之间的转换