-
Notifications
You must be signed in to change notification settings - Fork 70
/
getkeys.py
71 lines (58 loc) · 1.59 KB
/
getkeys.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
# -*- coding: utf-8 -*-
# Citation: Box Of Hats (https://github.com/Box-Of-Hats )
import win32api as wapi
import win32con as wcon
import time
keyList = ["\b"]
for char in "ABCDEFGHIJKLMNOPQRSTUVWXYZ 123456789,.'£$/\\":
keyList.append(char)
def key_check():
keys = []
for key in keyList:
if wapi.GetAsyncKeyState(ord(key)):
keys.append(key)
if wapi.GetAsyncKeyState(wcon.VK_UP):
keys.append('up')
if wapi.GetAsyncKeyState(wcon.VK_DOWN):
keys.append('down')
if wapi.GetAsyncKeyState(wcon.VK_RIGHT):
keys.append('right')
if wapi.GetAsyncKeyState(wcon.VK_LEFT):
keys.append('left')
if wapi.GetAsyncKeyState(wcon.VK_SPACE):
keys.append('space')
return keys
def keys_to_output_movement(keys):
"""
Convert keys to a ...multi-hot... array
['up - 0', 'down - 1', 'left - 2', 'right - 3', 'none - 4']
"""
output = [0, 0, 0, 0, 0]
if 'left' in keys:
output[2] = 1
elif 'up' in keys:
output[0] = 1
elif 'down' in keys:
output[1] = 1
elif 'right' in keys:
output[3] = 1
else:
output[4] = 1
return output
def keys_to_output_action(keys):
"""
Convert keys to a ...multi-hot... array
['shoot - 0 - space', 'pass - 1 - w', 'through - 2 - q', 'cross - 3 - f', 'none - 4']
"""
output = [0, 0, 0, 0, 0]
if 'space' in keys:
output[0] = 1
elif 'W' in keys:
output[1] = 1
elif 'Q' in keys:
output[2] = 1
elif 'F' in keys:
output[3] = 1
else:
output[4] = 1
return output