Skip to content

Instantly share code, notes, and snippets.

@zeevro
Last active Jan 1, 2018
Embed
What would you like to do?
A simple utility to simulate typing of unicode characters in Windows
/*
Compilation instructions:
1. Open VS developer console
2. cl.exe /Feunikey.exe unikey.c
3. You're done. It's that simple. :)
*/
#include <windows.h>
#include <stdio.h>
#pragma comment(lib, "user32")
#define PRINT_USAGE() printf("Usage: %s <codepoint> [<sleep time>]\n", argv[0])
int main(int argc, char * argv[])
{
int codepoint;
INPUT inputs[2];
if (argc < 2 || argc > 4)
{
PRINT_USAGE();
return 1;
}
codepoint = atoi(argv[1]);
if (!codepoint)
{
sscanf(argv[1], "%x", &codepoint);
if (!codepoint)
{
PRINT_USAGE();
return 2;
}
}
if (argc == 3)
{
Sleep(atoi(argv[2]));
}
memset(&inputs[0], 0, sizeof(inputs[0]));
inputs[0].type = INPUT_KEYBOARD;
inputs[0].ki.wScan = codepoint;
inputs[0].ki.dwFlags = KEYEVENTF_UNICODE;
memcpy(&inputs[1], &inputs[0], sizeof(inputs[0]));
inputs[1].ki.dwFlags |= KEYEVENTF_KEYUP;
codepoint = SendInput(2, inputs, sizeof(inputs[0]));
if (codepoint)
{
return 0;
}
return GetLastError();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment