SendInput
-
Does anyone have a solid example on how use SendInput(). All the examples that are out there, are in VB. Also, see my memcpy() statements. Am I copying a structure into a structure of a structure properly?
BOOL fNumLockState; BYTE keys[255]; INPUT inp[2]; KEYBDINPUT kbi; GetKeyboardState( keys ); // NumLock handling: fNumLockState = keys[VK_NUMLOCK]; if( !fNumLockState ) // Turn numlock on { kbi.wVk = VK_NUMLOCK; kbi.wScan = 0; // not needed kbi.dwFlags = 0; // press the key down kbi.time = 0; // use the default kbi.dwExtraInfo = 0; // not needed memcpy( &(inp[0].ki), &kbi, sizeof(kbi) ); inp[0].type = INPUT_KEYBOARD; kbi.dwFlags = KEYEVENTF_KEYUP; // release the key down memcpy( &(inp[1].ki), &kbi, sizeof(kbi) ); inp[1].type = INPUT_KEYBOARD; if( SendInput( 2, inp, sizeof(inp) ) != 2 ) { TRACE(_T("SendInput error [%d]"), GetLastError() ); } }
Marcus Make no little plans; they have no magic to stir your blood to action. Make big plans, aim high in work and hope -- Daniel Burnham -
Does anyone have a solid example on how use SendInput(). All the examples that are out there, are in VB. Also, see my memcpy() statements. Am I copying a structure into a structure of a structure properly?
BOOL fNumLockState; BYTE keys[255]; INPUT inp[2]; KEYBDINPUT kbi; GetKeyboardState( keys ); // NumLock handling: fNumLockState = keys[VK_NUMLOCK]; if( !fNumLockState ) // Turn numlock on { kbi.wVk = VK_NUMLOCK; kbi.wScan = 0; // not needed kbi.dwFlags = 0; // press the key down kbi.time = 0; // use the default kbi.dwExtraInfo = 0; // not needed memcpy( &(inp[0].ki), &kbi, sizeof(kbi) ); inp[0].type = INPUT_KEYBOARD; kbi.dwFlags = KEYEVENTF_KEYUP; // release the key down memcpy( &(inp[1].ki), &kbi, sizeof(kbi) ); inp[1].type = INPUT_KEYBOARD; if( SendInput( 2, inp, sizeof(inp) ) != 2 ) { TRACE(_T("SendInput error [%d]"), GetLastError() ); } }
Marcus Make no little plans; they have no magic to stir your blood to action. Make big plans, aim high in work and hope -- Daniel Burnhamfigured it out... the line:
if( SendInput( 2, inp, sizeof(inp) ) != 2 )
should be...if( SendInput( 2, inp, sizeof(INPUT) ) != 2 )
Marcus Make no little plans; they have no magic to stir your blood to action. Make big plans, aim high in work and hope -- Daniel Burnham