Skip to content

Instantly share code, notes, and snippets.

@eioo
Last active August 17, 2019 01:36
Show Gist options
  • Save eioo/2ae4011a9c9d54c6b0e590a213484535 to your computer and use it in GitHub Desktop.
Save eioo/2ae4011a9c9d54c6b0e590a213484535 to your computer and use it in GitHub Desktop.
module vrobot
/* This is C's INPUT struct
typedef struct tagINPUT {
DWORD type;
union {
MOUSEINPUT mi;
KEYBDINPUT ki;
HARDWAREINPUT hi;
} DUMMYUNIONNAME;
} INPUT, *PINPUT, *LPINPUT;
*/
#flag -lgdi32
#include "windows.h"
struct C.INPUT
pub fn type_stuff() {
mut input := &C.INPUT{!}
input.type = 1 // C.INPUT_KEYBOARD, for some reason
// I can't use this? "keyboard.v:22 function `` is private"
input.ki.wScan = C.MapVirtualKey(vkey, C.MAPVK_VK_TO_VSC)
input.ki.time = 0
input.ki.dwExtraInfo = 0
input.ki.wVk = 0x41 // 'A'
input.ki.dwFlags = 0
C.SendInput(1, &input, sizeof(C.INPUT))
input.ki.dwFlags = C.KEYEVENTF_KEYUP
C.SendInput(1, &input, sizeof(C.INPUT))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment