| 1 |
package windows |
| 2 |
|
| 3 |
// Virtual Key codes |
| 4 |
// https://docs.microsoft.com/en-us/windows/win32/inputdev/virtual-key-codes |
| 5 |
// |
| 6 |
//nolint:revive |
| 7 |
const ( |
| 8 |
VK_LBUTTON = 0x01 |
| 9 |
VK_RBUTTON = 0x02 |
| 10 |
VK_CANCEL = 0x03 |
| 11 |
VK_MBUTTON = 0x04 |
| 12 |
VK_XBUTTON1 = 0x05 |
| 13 |
VK_XBUTTON2 = 0x06 |
| 14 |
VK_BACK = 0x08 |
| 15 |
VK_TAB = 0x09 |
| 16 |
VK_CLEAR = 0x0C |
| 17 |
VK_RETURN = 0x0D |
| 18 |
VK_SHIFT = 0x10 |
| 19 |
VK_CONTROL = 0x11 |
| 20 |
VK_MENU = 0x12 |
| 21 |
VK_PAUSE = 0x13 |
| 22 |
VK_CAPITAL = 0x14 |
| 23 |
VK_KANA = 0x15 |
| 24 |
VK_HANGEUL = 0x15 |
| 25 |
VK_HANGUL = 0x15 |
| 26 |
VK_IME_ON = 0x16 |
| 27 |
VK_JUNJA = 0x17 |
| 28 |
VK_FINAL = 0x18 |
| 29 |
VK_HANJA = 0x19 |
| 30 |
VK_KANJI = 0x19 |
| 31 |
VK_IME_OFF = 0x1A |
| 32 |
VK_ESCAPE = 0x1B |
| 33 |
VK_CONVERT = 0x1C |
| 34 |
VK_NONCONVERT = 0x1D |
| 35 |
VK_ACCEPT = 0x1E |
| 36 |
VK_MODECHANGE = 0x1F |
| 37 |
VK_SPACE = 0x20 |
| 38 |
VK_PRIOR = 0x21 |
| 39 |
VK_NEXT = 0x22 |
| 40 |
VK_END = 0x23 |
| 41 |
VK_HOME = 0x24 |
| 42 |
VK_LEFT = 0x25 |
| 43 |
VK_UP = 0x26 |
| 44 |
VK_RIGHT = 0x27 |
| 45 |
VK_DOWN = 0x28 |
| 46 |
VK_SELECT = 0x29 |
| 47 |
VK_PRINT = 0x2A |
| 48 |
VK_EXECUTE = 0x2B |
| 49 |
VK_SNAPSHOT = 0x2C |
| 50 |
VK_INSERT = 0x2D |
| 51 |
VK_DELETE = 0x2E |
| 52 |
VK_HELP = 0x2F |
| 53 |
VK_LWIN = 0x5B |
| 54 |
VK_RWIN = 0x5C |
| 55 |
VK_APPS = 0x5D |
| 56 |
VK_SLEEP = 0x5F |
| 57 |
VK_NUMPAD0 = 0x60 |
| 58 |
VK_NUMPAD1 = 0x61 |
| 59 |
VK_NUMPAD2 = 0x62 |
| 60 |
VK_NUMPAD3 = 0x63 |
| 61 |
VK_NUMPAD4 = 0x64 |
| 62 |
VK_NUMPAD5 = 0x65 |
| 63 |
VK_NUMPAD6 = 0x66 |
| 64 |
VK_NUMPAD7 = 0x67 |
| 65 |
VK_NUMPAD8 = 0x68 |
| 66 |
VK_NUMPAD9 = 0x69 |
| 67 |
VK_MULTIPLY = 0x6A |
| 68 |
VK_ADD = 0x6B |
| 69 |
VK_SEPARATOR = 0x6C |
| 70 |
VK_SUBTRACT = 0x6D |
| 71 |
VK_DECIMAL = 0x6E |
| 72 |
VK_DIVIDE = 0x6F |
| 73 |
VK_F1 = 0x70 |
| 74 |
VK_F2 = 0x71 |
| 75 |
VK_F3 = 0x72 |
| 76 |
VK_F4 = 0x73 |
| 77 |
VK_F5 = 0x74 |
| 78 |
VK_F6 = 0x75 |
| 79 |
VK_F7 = 0x76 |
| 80 |
VK_F8 = 0x77 |
| 81 |
VK_F9 = 0x78 |
| 82 |
VK_F10 = 0x79 |
| 83 |
VK_F11 = 0x7A |
| 84 |
VK_F12 = 0x7B |
| 85 |
VK_F13 = 0x7C |
| 86 |
VK_F14 = 0x7D |
| 87 |
VK_F15 = 0x7E |
| 88 |
VK_F16 = 0x7F |
| 89 |
VK_F17 = 0x80 |
| 90 |
VK_F18 = 0x81 |
| 91 |
VK_F19 = 0x82 |
| 92 |
VK_F20 = 0x83 |
| 93 |
VK_F21 = 0x84 |
| 94 |
VK_F22 = 0x85 |
| 95 |
VK_F23 = 0x86 |
| 96 |
VK_F24 = 0x87 |
| 97 |
VK_NUMLOCK = 0x90 |
| 98 |
VK_SCROLL = 0x91 |
| 99 |
VK_OEM_NEC_EQUAL = 0x92 |
| 100 |
VK_OEM_FJ_JISHO = 0x92 |
| 101 |
VK_OEM_FJ_MASSHOU = 0x93 |
| 102 |
VK_OEM_FJ_TOUROKU = 0x94 |
| 103 |
VK_OEM_FJ_LOYA = 0x95 |
| 104 |
VK_OEM_FJ_ROYA = 0x96 |
| 105 |
VK_LSHIFT = 0xA0 |
| 106 |
VK_RSHIFT = 0xA1 |
| 107 |
VK_LCONTROL = 0xA2 |
| 108 |
VK_RCONTROL = 0xA3 |
| 109 |
VK_LMENU = 0xA4 |
| 110 |
VK_RMENU = 0xA5 |
| 111 |
VK_BROWSER_BACK = 0xA6 |
| 112 |
VK_BROWSER_FORWARD = 0xA7 |
| 113 |
VK_BROWSER_REFRESH = 0xA8 |
| 114 |
VK_BROWSER_STOP = 0xA9 |
| 115 |
VK_BROWSER_SEARCH = 0xAA |
| 116 |
VK_BROWSER_FAVORITES = 0xAB |
| 117 |
VK_BROWSER_HOME = 0xAC |
| 118 |
VK_VOLUME_MUTE = 0xAD |
| 119 |
VK_VOLUME_DOWN = 0xAE |
| 120 |
VK_VOLUME_UP = 0xAF |
| 121 |
VK_MEDIA_NEXT_TRACK = 0xB0 |
| 122 |
VK_MEDIA_PREV_TRACK = 0xB1 |
| 123 |
VK_MEDIA_STOP = 0xB2 |
| 124 |
VK_MEDIA_PLAY_PAUSE = 0xB3 |
| 125 |
VK_LAUNCH_MAIL = 0xB4 |
| 126 |
VK_LAUNCH_MEDIA_SELECT = 0xB5 |
| 127 |
VK_LAUNCH_APP1 = 0xB6 |
| 128 |
VK_LAUNCH_APP2 = 0xB7 |
| 129 |
VK_OEM_1 = 0xBA |
| 130 |
VK_OEM_PLUS = 0xBB |
| 131 |
VK_OEM_COMMA = 0xBC |
| 132 |
VK_OEM_MINUS = 0xBD |
| 133 |
VK_OEM_PERIOD = 0xBE |
| 134 |
VK_OEM_2 = 0xBF |
| 135 |
VK_OEM_3 = 0xC0 |
| 136 |
VK_OEM_4 = 0xDB |
| 137 |
VK_OEM_5 = 0xDC |
| 138 |
VK_OEM_6 = 0xDD |
| 139 |
VK_OEM_7 = 0xDE |
| 140 |
VK_OEM_8 = 0xDF |
| 141 |
VK_OEM_AX = 0xE1 |
| 142 |
VK_OEM_102 = 0xE2 |
| 143 |
VK_ICO_HELP = 0xE3 |
| 144 |
VK_ICO_00 = 0xE4 |
| 145 |
VK_PROCESSKEY = 0xE5 |
| 146 |
VK_ICO_CLEAR = 0xE6 |
| 147 |
VK_OEM_RESET = 0xE9 |
| 148 |
VK_OEM_JUMP = 0xEA |
| 149 |
VK_OEM_PA1 = 0xEB |
| 150 |
VK_OEM_PA2 = 0xEC |
| 151 |
VK_OEM_PA3 = 0xED |
| 152 |
VK_OEM_WSCTRL = 0xEE |
| 153 |
VK_OEM_CUSEL = 0xEF |
| 154 |
VK_OEM_ATTN = 0xF0 |
| 155 |
VK_OEM_FINISH = 0xF1 |
| 156 |
VK_OEM_COPY = 0xF2 |
| 157 |
VK_OEM_AUTO = 0xF3 |
| 158 |
VK_OEM_ENLW = 0xF4 |
| 159 |
VK_OEM_BACKTAB = 0xF5 |
| 160 |
VK_ATTN = 0xF6 |
| 161 |
VK_CRSEL = 0xF7 |
| 162 |
VK_EXSEL = 0xF8 |
| 163 |
VK_EREOF = 0xF9 |
| 164 |
VK_PLAY = 0xFA |
| 165 |
VK_ZOOM = 0xFB |
| 166 |
VK_NONAME = 0xFC |
| 167 |
VK_PA1 = 0xFD |
| 168 |
VK_OEM_CLEAR = 0xFE |
| 169 |
) |
| 170 |
|
| 171 |
// Mouse button constants. |
| 172 |
// https://docs.microsoft.com/en-us/windows/console/mouse-event-record-str |
| 173 |
// |
| 174 |
//nolint:revive |
| 175 |
const ( |
| 176 |
FROM_LEFT_1ST_BUTTON_PRESSED = 0x0001 |
| 177 |
RIGHTMOST_BUTTON_PRESSED = 0x0002 |
| 178 |
FROM_LEFT_2ND_BUTTON_PRESSED = 0x0004 |
| 179 |
FROM_LEFT_3RD_BUTTON_PRESSED = 0x0008 |
| 180 |
FROM_LEFT_4TH_BUTTON_PRESSED = 0x0010 |
| 181 |
) |
| 182 |
|
| 183 |
// Control key state constraints. |
| 184 |
// https://docs.microsoft.com/en-us/windows/console/key-event-record-str |
| 185 |
// https://docs.microsoft.com/en-us/windows/console/mouse-event-record-str |
| 186 |
// |
| 187 |
//nolint:revive |
| 188 |
const ( |
| 189 |
CAPSLOCK_ON = 0x0080 |
| 190 |
ENHANCED_KEY = 0x0100 |
| 191 |
LEFT_ALT_PRESSED = 0x0002 |
| 192 |
LEFT_CTRL_PRESSED = 0x0008 |
| 193 |
NUMLOCK_ON = 0x0020 |
| 194 |
RIGHT_ALT_PRESSED = 0x0001 |
| 195 |
RIGHT_CTRL_PRESSED = 0x0004 |
| 196 |
SCROLLLOCK_ON = 0x0040 |
| 197 |
SHIFT_PRESSED = 0x0010 |
| 198 |
) |
| 199 |
|
| 200 |
// Mouse event record event flags. |
| 201 |
// https://docs.microsoft.com/en-us/windows/console/mouse-event-record-str |
| 202 |
// |
| 203 |
//nolint:revive |
| 204 |
const ( |
| 205 |
MOUSE_MOVED = 0x0001 |
| 206 |
DOUBLE_CLICK = 0x0002 |
| 207 |
MOUSE_WHEELED = 0x0004 |
| 208 |
MOUSE_HWHEELED = 0x0008 |
| 209 |
) |
| 210 |
|
| 211 |
// Input Record Event Types |
| 212 |
// https://learn.microsoft.com/en-us/windows/console/input-record-str |
| 213 |
// |
| 214 |
//nolint:revive |
| 215 |
const ( |
| 216 |
FOCUS_EVENT = 0x0010 |
| 217 |
KEY_EVENT = 0x0001 |
| 218 |
MENU_EVENT = 0x0008 |
| 219 |
MOUSE_EVENT = 0x0002 |
| 220 |
WINDOW_BUFFER_SIZE_EVENT = 0x0004 |
| 221 |
) |
| 222 |
|
| 223 |
// KeyEventRecord corresponds to the KeyEventRecord structure from the Windows |
| 224 |
// console API. |
| 225 |
// https://docs.microsoft.com/en-us/windows/console/key-event-record-str |
| 226 |
type KeyEventRecord struct { |
| 227 |
// KeyDown specified whether the key is pressed or released. |
| 228 |
KeyDown bool |
| 229 |
|
| 230 |
// RepeatCount indicates that a key is being held down. For example, when a |
| 231 |
// key is held down, five events with RepeatCount equal to 1 may be |
| 232 |
// generated, one event with RepeatCount equal to 5, or multiple events |
| 233 |
// with RepeatCount greater than or equal to 1. |
| 234 |
RepeatCount uint16 |
| 235 |
|
| 236 |
// VirtualKeyCode identifies the given key in a device-independent manner |
| 237 |
// (see |
| 238 |
// https://docs.microsoft.com/en-us/windows/win32/inputdev/virtual-key-codes). |
| 239 |
VirtualKeyCode uint16 |
| 240 |
|
| 241 |
// VirtualScanCode represents the device-dependent value generated by the |
| 242 |
// keyboard hardware. |
| 243 |
VirtualScanCode uint16 |
| 244 |
|
| 245 |
// Char is the character that corresponds to the pressed key. Char can be |
| 246 |
// zero for some keys. |
| 247 |
Char rune |
| 248 |
|
| 249 |
// ControlKeyState holds the state of the control keys. |
| 250 |
ControlKeyState uint32 |
| 251 |
} |
| 252 |
|
| 253 |
// InputRecord corresponds to the INPUT_RECORD structure from the Windows |
| 254 |
// console API. |
| 255 |
// |
| 256 |
// https://docs.microsoft.com/en-us/windows/console/input-record-str |
| 257 |
type InputRecord struct { |
| 258 |
// EventType specifies the type of event that helt in Event. |
| 259 |
EventType uint16 |
| 260 |
|
| 261 |
// Padding of the 16-bit EventType to a whole 32-bit dword. |
| 262 |
_ [2]byte |
| 263 |
|
| 264 |
// Event holds the actual event data. |
| 265 |
Event [16]byte |
| 266 |
} |