Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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
# These keys don't work on X11 with pynput because they are not usually
# 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.
NUMPAD3 = KeyCode.from_vk(0xffb3)
NUMPAD4 = KeyCode.from_vk(0xffb4)
NUMPAD5 = KeyCode.from_vk(0xffb5)
NUMPAD6 = KeyCode.from_vk(0xffb6)
NUMPAD7 = KeyCode.from_vk(0xffb7)
NUMPAD8 = KeyCode.from_vk(0xffb8)
NUMPAD9 = KeyCode.from_vk(0xffb9)
# Function keys F21-F24.
# Retrieved from /usr/include/X11/keysymdef.h on Debian 9.
# These keys don't work on X11 with pynput because they are not usually
# 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)
# 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).
"""
def press_release(self,virtual_key_id):
key = KeyCode.from_vk(virtual_key_id)
self.keyboard.press(key)
self.keyboard.release(key)
# 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).
"""
# Extra function keys.
F21 = virtual_keys.f21
F22 = virtual_keys.f22
F23 = virtual_keys.f23
# Number pad keys
# Retrieved from /usr/include/X11/keysymdef.h on Debian 9.
MULTIPLY = KeyCode.from_vk(0xffaa)
ADD = KeyCode.from_vk(0xffab)
SEPARATOR = KeyCode.from_vk(0xffac)
SUBTRACT = KeyCode.from_vk(0xffad)
DECIMAL = KeyCode.from_vk(0xffae)
DIVIDE = KeyCode.from_vk(0xffaf)
NUMPAD0 = KeyCode.from_vk(0xffb0)
NUMPAD1 = KeyCode.from_vk(0xffb1)
NUMPAD2 = KeyCode.from_vk(0xffb2)
NUMPAD3 = KeyCode.from_vk(0xffb3)
NUMPAD4 = KeyCode.from_vk(0xffb4)
NUMPAD5 = KeyCode.from_vk(0xffb5)
NUMPAD6 = KeyCode.from_vk(0xffb6)
NUMPAD7 = KeyCode.from_vk(0xffb7)
NUMPAD8 = KeyCode.from_vk(0xffb8)
NUMPAD9 = KeyCode.from_vk(0xffb9)
# Function keys F21-F24.
# Retrieved from /usr/include/X11/keysymdef.h on Debian 9.
# These keys don't work on X11 with pynput because they are not usually
# 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
class X11KeySymbols(BaseKeySymbols):
"""
Symbols for X11 from pynput.
This class includes extra symbols matching those that dragonfly's Win32
keyboard interface provides.
"""
# Number pad keys
# Retrieved from /usr/include/X11/keysymdef.h on Debian 9.
MULTIPLY = KeyCode.from_vk(0xffaa)
ADD = KeyCode.from_vk(0xffab)
SEPARATOR = KeyCode.from_vk(0xffac)
SUBTRACT = KeyCode.from_vk(0xffad)
DECIMAL = KeyCode.from_vk(0xffae)
DIVIDE = KeyCode.from_vk(0xffaf)
NUMPAD0 = KeyCode.from_vk(0xffb0)
NUMPAD1 = KeyCode.from_vk(0xffb1)
NUMPAD2 = KeyCode.from_vk(0xffb2)
NUMPAD3 = KeyCode.from_vk(0xffb3)
NUMPAD4 = KeyCode.from_vk(0xffb4)
NUMPAD5 = KeyCode.from_vk(0xffb5)
NUMPAD6 = KeyCode.from_vk(0xffb6)
NUMPAD7 = KeyCode.from_vk(0xffb7)
NUMPAD8 = KeyCode.from_vk(0xffb8)
NUMPAD9 = KeyCode.from_vk(0xffb9)
# Function keys F21-F24.
# Retrieved from /usr/include/X11/keysymdef.h on Debian 9.
# These keys don't work on X11 with pynput because they are not usually
# part of the keyboard map. They are set here to avoid some warnings
# and because the Windows keyboard supports them.
# Number pad keys
# Retrieved from /usr/include/X11/keysymdef.h on Debian 9.
MULTIPLY = KeyCode.from_vk(0xffaa)
ADD = KeyCode.from_vk(0xffab)
SEPARATOR = KeyCode.from_vk(0xffac)
SUBTRACT = KeyCode.from_vk(0xffad)
DECIMAL = KeyCode.from_vk(0xffae)
DIVIDE = KeyCode.from_vk(0xffaf)
NUMPAD0 = KeyCode.from_vk(0xffb0)
NUMPAD1 = KeyCode.from_vk(0xffb1)
NUMPAD2 = KeyCode.from_vk(0xffb2)
NUMPAD3 = KeyCode.from_vk(0xffb3)
NUMPAD4 = KeyCode.from_vk(0xffb4)
NUMPAD5 = KeyCode.from_vk(0xffb5)
NUMPAD6 = KeyCode.from_vk(0xffb6)
NUMPAD7 = KeyCode.from_vk(0xffb7)
NUMPAD8 = KeyCode.from_vk(0xffb8)
NUMPAD9 = KeyCode.from_vk(0xffb9)
# Function keys F21-F24.
# Retrieved from /usr/include/X11/keysymdef.h on Debian 9.
# These keys don't work on X11 with pynput because they are not usually
# 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.
NUMPAD2 = KeyCode.from_vk(0xffb2)
NUMPAD3 = KeyCode.from_vk(0xffb3)
NUMPAD4 = KeyCode.from_vk(0xffb4)
NUMPAD5 = KeyCode.from_vk(0xffb5)
NUMPAD6 = KeyCode.from_vk(0xffb6)
NUMPAD7 = KeyCode.from_vk(0xffb7)
NUMPAD8 = KeyCode.from_vk(0xffb8)
NUMPAD9 = KeyCode.from_vk(0xffb9)
# Function keys F21-F24.
# Retrieved from /usr/include/X11/keysymdef.h on Debian 9.
# These keys don't work on X11 with pynput because they are not usually
# 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)