Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def normalize(event):
if not isinstance(event[0], tuple):
return normalize(((event[0],), event[1]))
key, is_pressed = event
return (
tuple(
pynput.keyboard.KeyCode.from_char(key)
if isinstance(key, six.string_types)
else key.value if key in pynput.keyboard.Key
else key
for key in event[0]),
is_pressed)
def run(self):
while self.execute_count > 0:
with open(self.file_name, 'r', encoding='utf-8') as file:
keyboard_exec = KeyBoardController()
line = file.readline()
while line:
obj = json.loads(line)
if obj['name'] == 'keyboard':
if obj['event'] == 'press':
keyboard_exec.press(KeyCode.from_vk(obj['vk']))
time.sleep(0.01)
elif obj['event'] == 'release':
keyboard_exec.release(KeyCode.from_vk(obj['vk']))
time.sleep(0.01)
line = file.readline()
startExecuteBtn['text'] = '开始回放'
startExecuteBtn['state'] = 'normal'
self.execute_count = self.execute_count - 1
PAGE_DOWN = virtual_keys.page_down
HOME = virtual_keys.home
END = virtual_keys.end
# Number pad keys
# pynput currently only exposes these for Windows, so we'll map them to
# equivalent characters and numbers instead.
MULTIPLY = KeyCode(char="*")
ADD = KeyCode(char="+")
SEPARATOR = KeyCode(char=".") # this is locale-dependent.
SUBTRACT = KeyCode(char="-")
DECIMAL = KeyCode(char=".")
DIVIDE = KeyCode(char="/")
NUMPAD0 = KeyCode(char="0")
NUMPAD1 = KeyCode(char="1")
NUMPAD2 = KeyCode(char="2")
NUMPAD3 = KeyCode(char="3")
NUMPAD4 = KeyCode(char="4")
NUMPAD5 = KeyCode(char="5")
NUMPAD6 = KeyCode(char="6")
NUMPAD7 = KeyCode(char="7")
NUMPAD8 = KeyCode(char="8")
NUMPAD9 = KeyCode(char="9")
# Function keys
# F13-20 don't work on X11 with pynput because they are not usually
# part of the keyboard map.
F1 = virtual_keys.f1
F2 = virtual_keys.f2
F3 = virtual_keys.f3
F4 = virtual_keys.f4
F5 = virtual_keys.f5
LEFT = virtual_keys.left
RIGHT = virtual_keys.right
PAGE_UP = virtual_keys.page_up
PAGE_DOWN = virtual_keys.page_down
HOME = virtual_keys.home
END = virtual_keys.end
# Number pad keys
# pynput currently only exposes these for Windows, so we'll map them to
# equivalent characters and numbers instead.
MULTIPLY = KeyCode(char="*")
ADD = KeyCode(char="+")
SEPARATOR = KeyCode(char=".") # this is locale-dependent.
SUBTRACT = KeyCode(char="-")
DECIMAL = KeyCode(char=".")
DIVIDE = KeyCode(char="/")
NUMPAD0 = KeyCode(char="0")
NUMPAD1 = KeyCode(char="1")
NUMPAD2 = KeyCode(char="2")
NUMPAD3 = KeyCode(char="3")
NUMPAD4 = KeyCode(char="4")
NUMPAD5 = KeyCode(char="5")
NUMPAD6 = KeyCode(char="6")
NUMPAD7 = KeyCode(char="7")
NUMPAD8 = KeyCode(char="8")
NUMPAD9 = KeyCode(char="9")
# Function keys
# F13-20 don't work on X11 with pynput because they are not usually
# part of the keyboard map.
F1 = virtual_keys.f1
F2 = virtual_keys.f2
def key_event(key, is_press):
if not self.recording or self.running:
return True
if is_press:
print('keyboard press:', key)
message = 'key down'
else:
print('keyboard release:', key)
message = 'key up'
if isinstance(key, Key):
print('Key:', key.name, key.value.vk)
name = key.name
elif isinstance(key, KeyCode):
print('KeyCode:', key.char, key.vk)
name = key.char
else:
assert False
delay = self.now_ts - self.ttt
self.ttt = self.now_ts
if not self.record:
delay = 0
self.record.append([delay, 'EK', message, name])
text = self.tnumrd.GetLabel()
text = text.replace(' actions recorded', '')
text = str(eval(text) + 1)
MULTIPLY = KeyCode(char="*")
ADD = KeyCode(char="+")
SEPARATOR = KeyCode(char=".") # this is locale-dependent.
SUBTRACT = KeyCode(char="-")
DECIMAL = KeyCode(char=".")
DIVIDE = KeyCode(char="/")
NUMPAD0 = KeyCode(char="0")
NUMPAD1 = KeyCode(char="1")
NUMPAD2 = KeyCode(char="2")
NUMPAD3 = KeyCode(char="3")
NUMPAD4 = KeyCode(char="4")
NUMPAD5 = KeyCode(char="5")
NUMPAD6 = KeyCode(char="6")
NUMPAD7 = KeyCode(char="7")
NUMPAD8 = KeyCode(char="8")
NUMPAD9 = KeyCode(char="9")
# Function keys
# F13-20 don't work on X11 with pynput because they are not usually
# part of the keyboard map.
F1 = virtual_keys.f1
F2 = virtual_keys.f2
F3 = virtual_keys.f3
F4 = virtual_keys.f4
F5 = virtual_keys.f5
F6 = virtual_keys.f6
F7 = virtual_keys.f7
F8 = virtual_keys.f8
F9 = virtual_keys.f9
F10 = virtual_keys.f10
F11 = virtual_keys.f11
F12 = virtual_keys.f12
Key.enter: "enter",
Key.f1: "F1",
Key.f2: "F2",
Key.f3: "F3",
Key.f4: "F4",
Key.f5: "F5",
Key.f6: "F6",
Key.f7: "F7",
Key.f8: "F8",
Key.f9: "F9",
Key.f10: "F10",
Key.f11: "F11",
Key.f12: "F12",
}
pynput_rgb_keys.update({KeyCode(char=item): item for item in alphanumeric})
if __name__ == '__main__':
print(len(alphanumeric) + len(functionkeys) + len(modifiers) + len(keypad) + len(controls))
# part of the keyboard map. They are set here to avoid some warnings
# and because the Windows keyboard supports them.
F21 = KeyCode.from_vk(0xffd1)
F22 = KeyCode.from_vk(0xffd2)
F23 = KeyCode.from_vk(0xffd3)
F24 = KeyCode.from_vk(0xffd4)
# Multimedia keys
# Retrieved from /usr/include/X11/XF86keysym.h on Debian 9.
# These should work on Debian-based distributions like Ubunutu, but
# might not work using different X11 server implementations because the
# symbols are vendor-specific.
# Any errors raised when typing these or any other keys will be caught
# and logged.
VOLUME_UP = KeyCode.from_vk(0x1008FF13)
VOLUME_DOWN = KeyCode.from_vk(0x1008FF11)
VOLUME_MUTE = KeyCode.from_vk(0x1008FF12)
MEDIA_NEXT_TRACK = KeyCode.from_vk(0x1008FF17)
MEDIA_PREV_TRACK = KeyCode.from_vk(0x1008FF16)
MEDIA_PLAY_PAUSE = KeyCode.from_vk(0x1008FF14)
BROWSER_BACK = KeyCode.from_vk(0x1008FF26)
BROWSER_FORWARD = KeyCode.from_vk(0x1008FF27)
class DarwinKeySymbols(BaseKeySymbols):
"""
Symbols for Darwin from pynput.
This class includes some extra symbols to prevent errors in
typeables.py.
All extras will be disabled (key code of -1).
# Number pad keys
# pynput currently only exposes these for Windows, so we'll map them to
# equivalent characters and numbers instead.
MULTIPLY = KeyCode(char="*")
ADD = KeyCode(char="+")
SEPARATOR = KeyCode(char=".") # this is locale-dependent.
SUBTRACT = KeyCode(char="-")
DECIMAL = KeyCode(char=".")
DIVIDE = KeyCode(char="/")
NUMPAD0 = KeyCode(char="0")
NUMPAD1 = KeyCode(char="1")
NUMPAD2 = KeyCode(char="2")
NUMPAD3 = KeyCode(char="3")
NUMPAD4 = KeyCode(char="4")
NUMPAD5 = KeyCode(char="5")
NUMPAD6 = KeyCode(char="6")
NUMPAD7 = KeyCode(char="7")
NUMPAD8 = KeyCode(char="8")
NUMPAD9 = KeyCode(char="9")
# Function keys
# F13-20 don't work on X11 with pynput because they are not usually
# part of the keyboard map.
F1 = virtual_keys.f1
F2 = virtual_keys.f2
F3 = virtual_keys.f3
F4 = virtual_keys.f4
F5 = virtual_keys.f5
F6 = virtual_keys.f6
F7 = virtual_keys.f7
F8 = virtual_keys.f8
F9 = virtual_keys.f9