Skip to content

Instantly share code, notes, and snippets.

@kusa-mochi
Created May 16, 2020 01:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kusa-mochi/82c3c2a65cf4bb3c560ec56f4029e594 to your computer and use it in GitHub Desktop.
Save kusa-mochi/82c3c2a65cf4bb3c560ec56f4029e594 to your computer and use it in GitHub Desktop.
// キーコード
short key = 65;
INPUT[] inputs = new INPUT[] {
new INPUT {
type = NativeMethods.INPUT_KEYBOARD,
ui = new INPUT_UNION {
keyboard = new KEYBDINPUT {
wVk = key,
wScan = (short) NativeMethods.MapVirtualKey (key, 0),
dwFlags = NativeMethods.KEYEVENTF_EXTENDEDKEY | NativeMethods.KEYEVENTF_KEYDOWN, // キーの押し下げ
dwExtraInfo = IntPtr.Zero,
time = 0
}
}
},
new INPUT {
type = NativeMethods.INPUT_KEYBOARD,
ui = new INPUT_UNION {
keyboard = new KEYBDINPUT {
wVk = key,
wScan = (short) NativeMethods.MapVirtualKey (key, 0),
dwFlags = NativeMethods.KEYEVENTF_EXTENDEDKEY | NativeMethods.KEYEVENTF_KEYUP, // キーの押し上げ
dwExtraInfo = IntPtr.Zero,
time = 0
}
}
}
};
NativeMethods.SendInput (2, ref inputs[0], Marshal.SizeOf (inputs[0]));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment