Skip to content

Instantly share code, notes, and snippets.

@ijkilchenko
Created May 23, 2019 05:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ijkilchenko/49a912ce06bb73021c82359aa4f387b6 to your computer and use it in GitHub Desktop.
Save ijkilchenko/49a912ce06bb73021c82359aa4f387b6 to your computer and use it in GitHub Desktop.
import keyboard
import time
if __name__ == '__main__':
frames = [0]
def forward():
global last_frame_index
while True:
if not is_paused:
last_frame = frames[-1]
new_frame = last_frame + 1
frames.append(new_frame)
last_frame_index = len(frames) - 1
print('Forward\t[%d]' % new_frame)
time.sleep(0.01)
def resume(*args):
global hook
keyboard.unhook(hook)
hook = keyboard.on_press_key('k', pause)
global is_paused
is_paused = False
def pause(*args):
global hook
keyboard.unhook(hook)
hook = keyboard.on_press_key('k', resume)
global is_paused
is_paused = True
def rewind(*args):
global last_frame_index
last_frame_index += -1
try:
print('Rewind\t[%d]' % frames[last_frame_index])
except IndexError:
last_frame_index = 0
pause()
def fastforward(*args):
global last_frame_index
last_frame_index += 1
try:
print('FastForward\t[%d]' % frames[last_frame_index])
except IndexError:
last_frame_index = len(frames)
pause()
global hook
hook = keyboard.on_press_key('k', pause)
keyboard.on_press_key('j', rewind)
keyboard.on_press_key('l', fastforward)
is_paused = False
forward()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment