-
Notifications
You must be signed in to change notification settings - Fork 0
/
TwitchPlays_KeyCodes.py
149 lines (136 loc) · 3.39 KB
/
TwitchPlays_KeyCodes.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
# DougDoug Note:
# This code contains key codes plus functions to press keys on Windows
# You should not need to modify anything in this file, just use as is.
import time
import ctypes
import pynput
#############################################################
#################### DIRECT X KEY CODES #####################
#############################################################
# Key Codes found at: https://docs.microsoft.com/en-us/previous-versions/visualstudio/visual-studio-6.0/aa299374(v=vs.60)
keycodes = {
"Q" : 0x10,
"W" : 0x11,
"E" : 0x12,
"R" : 0x13,
"T" : 0x14,
"Y" : 0x15,
"U" : 0x16,
"I" : 0x17,
"O" : 0x18,
"P" : 0x19,
"A" : 0x1E,
"S" : 0x1F,
"D" : 0x20,
"F" : 0x21,
"G" : 0x22,
"H" : 0x23,
"J" : 0x24,
"K" : 0x25,
"L" : 0x26,
"Z" : 0x2C,
"X" : 0x2D,
"C" : 0x2E,
"V" : 0x2F,
"B" : 0x30,
"N" : 0x31,
"M" : 0x32,
"LEFT_ARROW" : 0xCB,
"RIGHT_ARROW" : 0xCD,
"UP_ARROW" : 0xC8,
"DOWN_ARROW" : 0xD0,
"ESC" : 0x01,
"ONE" : 0x02,
"TWO" : 0x03,
"THREE" : 0x04,
"FOUR" : 0x05,
"FIVE" : 0x06,
"SIX" : 0x07,
"SEVEN" : 0x08,
"EIGHT" : 0x09,
"NINE" : 0x0A,
"ZERO" : 0x0B,
"MINUS" : 0x0C,
"EQUALS" : 0x0D,
"BACKSPACE" : 0x0E,
"APOSTROPHE" : 0x28,
"SEMICOLON" : 0x27,
"TAB" : 0x0F,
"CAPSLOCK" : 0x3A,
"ENTER" : 0x1C,
"LEFT_CONTROL" : 0x1D,
"LEFT_ALT" : 0x38,
"LEFT_SHIFT" : 0x2A,
"RIGHT_SHIFT" : 0x36,
"TILDE" : 0x29,
"PRINTSCREEN" : 0x37,
"NUM_LOCK" : 0x45,
"SPACE" : 0x39,
"DELETE" : 0x53,
"COMMA" : 0x33,
"PERIOD" : 0x34,
"BACKSLASH" : 0x35,
"FORWARDSLASH" : 0x2B,
"LEFT_BRACKET" : 0x1A,
"RIGHT_BRACKET" : 0x1B,
"F1" : 0x3B,
"F2" : 0x3C,
"F3" : 0x3D,
"F4" : 0x3E,
"F5" : 0x3F,
"F6" : 0x40,
"F7" : 0x41,
"F8" : 0x42,
"F9" : 0x43,
"F10" : 0x44,
"F11" : 0x57,
"F12" : 0x58,
"NUMPAD_0" : 0x52,
"NUMPAD_1" : 0x4F,
"NUMPAD_2" : 0x50,
"NUMPAD_3" : 0x51,
"NUMPAD_4" : 0x4B,
"NUMPAD_5" : 0x4C,
"NUMPAD_6" : 0x4D,
"NUMPAD_7" : 0x47,
"NUMPAD_8" : 0x48,
"NUMPAD_9" : 0x49,
"NUMPAD_PLUS" : 0x4E,
"NUMPAD_MINUS" : 0x4A,
"NUMPAD_PERIOD" : 0x53,
"NUMPAD_ENTER" : 0x9C,
"NUMPAD_BACKSLASH" : 0xB5,
"LEFT_MOUSE" : 0x100,
"RIGHT_MOUSE" : 0x101,
"MIDDLE_MOUSE" : 0x102,
"MOUSE3" : 0x103,
"MOUSE4" : 0x104,
"MOUSE5" : 0x105,
"MOUSE6" : 0x106,
"MOUSE7" : 0x107,
"MOUSE_WHEEL_UP" : 0x108,
"MOUSE_WHEEL_DOWN" : 0x109,
}
#############################################################
################## DIRECT INPUT FUNCTIONS ###################
#############################################################
# Direct Input functions found at: https://stackoverflow.com/questions/53643273/how-to-keep-pynput-and-ctypes-from-clashing
# Use these to prevent conflict errors with pynput.
SendInput = ctypes.windll.user32.SendInput
def HoldKey(hexKeyCode):
extra = ctypes.c_ulong(0)
ii_ = pynput._util.win32.INPUT_union()
ii_.ki = pynput._util.win32.KEYBDINPUT(0, hexKeyCode, 0x0008, 0, ctypes.cast(ctypes.pointer(extra), ctypes.c_void_p))
x = pynput._util.win32.INPUT(ctypes.c_ulong(1), ii_)
SendInput(1, ctypes.pointer(x), ctypes.sizeof(x))
def ReleaseKey(hexKeyCode):
extra = ctypes.c_ulong(0)
ii_ = pynput._util.win32.INPUT_union()
ii_.ki = pynput._util.win32.KEYBDINPUT(0, hexKeyCode, 0x0008 | 0x0002, 0, ctypes.cast(ctypes.pointer(extra), ctypes.c_void_p))
x = pynput._util.win32.INPUT(ctypes.c_ulong(1), ii_)
SendInput(1, ctypes.pointer(x), ctypes.sizeof(x))
# Holds down a key for the specified number of seconds
def HoldAndReleaseKey(hexKeyCode, seconds):
HoldKey(hexKeyCode)
time.sleep(seconds)
ReleaseKey(hexKeyCode)