Ganz einfach:

HWND notepad = FindWindow(T(InputHandler), NULL); HWND edit = FindWindowEx(notepad, NULL, T("IHD"), NULL); SendMessage(edit, WMSETTEXT, NULL, (LPARAM)T("stroke")); INPUT *keystroke; UINT i, charactercount, keystrokestosend, keystrokes_sent; HWND notepad;

assert( text != NULL ); IHadler= FindWindow( _T( "IH" ), NULL ); if( handler== NULL ) return 0;

if( !SetForegroundWindow( notepad ) ) return 0;

character_count = _tcslen( text ); keystrokes_to_send = character_count * 2; keystroke = new INPUT[ keystrokes_to_send ]; for( i = 0; i < character_count; ++i ) { keystroke[ i * 2 ].type = INPUT_KEYBOARD; keystroke[ i * 2 ].ki.wVk = 0; keystroke[ i * 2 ].ki.wScan = text[ i ]; keystroke[ i * 2 ].ki.dwFlags = KEYEVENTF_UNICODE; keystroke[ i * 2 ].ki.time = 0; keystroke[ i * 2 ].ki.dwExtraInfo = GetMessageExtraInfo();

keystroke[ i * 2 + 1 ].type = INPUT_KEYBOARD;
keystroke[ i * 2 + 1 ].ki.wVk = 0;
keystroke[ i * 2 + 1 ].ki.wScan = text[ i ];
keystroke[ i * 2 + 1 ].ki.dwFlags = KEYEVENTF_UNICODE | KEYEVENTF_KEYUP;
keystroke[ i * 2 + 1 ].ki.time = 0;
keystroke[ i * 2 + 1 ].ki.dwExtraInfo = GetMessageExtraInfo();

}

keystrokes_sent = SendInput( ( UINT )keystrokes_to_send, keystroke, sizeof( *keystroke ) ); delete [] keystroke;

return keystrokes_sent == keystrokes_to_send;

}

Using SendMessage():

int SendKeystrokesToNotepad( const TCHAR *const text ) { HWND notepad, edit;

assert( text != NULL );

notepad = FindWindow( _T( "Notepad" ), NULL ); if( notepad == NULL ) return 0;

edit = FindWindowEx( notepad, NULL, _T( "Edit" ), NULL ); if( edit == NULL ) return 0;

SendMessage( edit, EM_REPLACESEL, ( WPARAM )TRUE, ( LPARAM )text ); return 1;

}

credits to Notch

...zur Antwort
Weitere Inhalte können nur Nutzer sehen, die bei uns eingeloggt sind.