掲示板システム
ホーム
アクセス解析
カテゴリ
ログアウト
キーボードイベントの送信 (ID:62507)
名前
ホームページ(ブログ、Twitterなど)のURL (省略可)
本文
keybd_eventを使う前にSetForegroundWindow関数で目的のウインドウに フォーカスを移してから行ってみては? また、keybd_eventではなくSendInput関数で記述するのはどうかな? #define _WIN32_WINNT (0x0500) #include <windows.h> /* キーの設定用関数 */ static VOID FuncSetKeybrd( LPINPUT lpKey, WORD wVKey, BOOL bKeyDown ) { lpKey->type = INPUT_KEYBOARD; lpKey->ki.wVk = wVKey; lpKey->ki.wScan = (WORD)MapVirtualKey( wVKey, 0 ); lpKey->ki.dwFlags = (bKeyDown ? 0 : KEYEVENTF_KEYUP); lpKey->ki.dwExtraInfo = 0; lpKey->ki.time = 0; } /* キーボードイベントの送信 */ static VOID FuncExecWinKey( VOID ) { INPUT Key[ 16 ]; LPINPUT lpKey = Key; FuncSetKeybrd( lpKey++, 'A', TRUE ); // 'A'キーを押す FuncSetKeybrd( lpKey++, 'A', FALSE ); // 'A'キーを離す FuncSetKeybrd( lpKey++, 'B', TRUE ); FuncSetKeybrd( lpKey++, 'B', FALSE ); FuncSetKeybrd( lpKey++, 'C', TRUE ); FuncSetKeybrd( lpKey++, 'C', FALSE ); FuncSetKeybrd( lpKey++, VK_CONTROL, TRUE ); FuncSetKeybrd( lpKey++, 'J', TRUE ); FuncSetKeybrd( lpKey++, 'J', FALSE ); FuncSetKeybrd( lpKey++, VK_CONTROL, FALSE ); FuncSetKeybrd( lpKey++, '1', TRUE ); FuncSetKeybrd( lpKey++, '1', FALSE ); FuncSetKeybrd( lpKey++, '2', TRUE ); FuncSetKeybrd( lpKey++, '2', FALSE ); FuncSetKeybrd( lpKey++, '3', TRUE ); FuncSetKeybrd( lpKey++, '3', FALSE ); SetForegroundWindow( FindWindow(TEXT("Notepad"),NULL) ); // メモ帳のウインドウハンドルを検索&設定 SendInput( (UINT)(lpKey - Key), Key, sizeof(INPUT) ); } /* ●動作 ①"ABC"を入力 ②[改行]を入力 ③"123"を入力 */
←解決時は質問者本人がここをチェックしてください。
更新する
戻る
掲示板システム
Copyright 2021 Takeshi Okamoto All Rights Reserved.