Skip to content

Instantly share code, notes, and snippets.

@orange-in-space
Last active September 18, 2018 03:05
Show Gist options
  • Save orange-in-space/c3be3015d2e0fa60b9e1aaa274cfbad6 to your computer and use it in GitHub Desktop.
Save orange-in-space/c3be3015d2e0fa60b9e1aaa274cfbad6 to your computer and use it in GitHub Desktop.
minimal send key input app for windows(lazy)(キー入力を送るだけのやつ>< Windows用手抜き)
// SimpleSendKeys.cpp
//
// (c) orange_in_space, 2018
// Licence: CC0
//
// HowToUse:
// SimpleSendKeys.exe VK_keycode(in Hex)
//
// Build:
// VC++2017 "/SUBSYSTEM:WINDOWS"
//
//#include "pch.h"
#include <iostream>
#include <windows.h>
void SendKey(WORD keycode)
{
INPUT data;
memset(&data, 0, sizeof(data));
data.type = INPUT_KEYBOARD;
data.ki.wVk = keycode;
data.ki.wScan = MapVirtualKey(keycode, 0);
data.ki.dwFlags = KEYEVENTF_EXTENDEDKEY;
SendInput(1, &data, sizeof(INPUT));
data.ki.dwFlags = KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP;
SendInput(1, &data, sizeof(INPUT));
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
int nArgs;
LPTSTR *lplpszArgs;
lplpszArgs = CommandLineToArgvW(GetCommandLine(), &nArgs);
unsigned int vkkeycode = 0;
if (nArgs > 1)
{
swscanf_s(lplpszArgs[1], L"%x", &vkkeycode);
}
LocalFree(lplpszArgs);
if (vkkeycode > 0)
{
WORD keycode = vkkeycode;
SendKey(keycode);
}
return 0;
//VK_LWIN 0x5B
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment