Skip to content

Instantly share code, notes, and snippets.

@deton
Created October 14, 2020 23:21
Show Gist options
  • Select an option

  • Save deton/1c5f71f77d4ba1456297276efada0531 to your computer and use it in GitHub Desktop.

Select an option

Save deton/1c5f71f77d4ba1456297276efada0531 to your computer and use it in GitHub Desktop.
VK_IME_ON, VK_IME_OFFをkeybd_event()で送り付ける
// vkimeonofftest.cpp: VK_IME_ON, VK_IME_OFFをkeybd_event()で送付
// Compile: cl.exe vkimeonofftest.cpp user32.lib
//
// based on https://www.inasoft.org/autokeyb/chapter2.html
// キーボードシミュレータ(C++ ネイディブ版)
// Copyright(C) 2006 T.Yabuki
#define WIN32_LEAN_AND_MEAN // Windows ヘッダーから使用されていない部分を除外します。
#include <windows.h>
#include <stdio.h>
// 入力対象のプログラムをアクティブにするまでの待ち時間(ミリ秒単位)
DWORD dwSleepTime = 5000;
// キーの取りこぼしを防ぐための、各入力間の待機時間(ミリ秒単位)
DWORD dwWaitTime = 10;
int main(int argc, char* argv[])
{
puts("入力対象のプログラムをアクティブにしてください。");
printf("%uミリ秒間待機します...", dwSleepTime);
Sleep(dwSleepTime);
puts("\n入力中...");
// VK_IME_ON
keybd_event(0x16, 0, 0, 0);
keybd_event(0x16, 0, KEYEVENTF_KEYUP, 0);
Sleep(dwWaitTime);
keybd_event('A', 0, 0, 0);
keybd_event('A', 0, KEYEVENTF_KEYUP, 0);
Sleep(dwWaitTime);
keybd_event(VK_RETURN, 0, 0, 0);
keybd_event(VK_RETURN, 0, KEYEVENTF_KEYUP, 0);
Sleep(dwWaitTime);
Sleep(2000);
// VK_IME_OFF
keybd_event(0x1A, 0, 0, 0);
keybd_event(0x1A, 0, KEYEVENTF_KEYUP, 0);
Sleep(dwWaitTime);
keybd_event('A', 0, 0, 0);
keybd_event('A', 0, KEYEVENTF_KEYUP, 0);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment