Created
May 2, 2016 03:02
-
-
Save boppreh/5bb2dfe112530734ff68f5dd58c0815b to your computer and use it in GitHub Desktop.
Keyboard recorder for screencasts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import keyboard | |
import pickle | |
import os | |
if len(sys.argv) == 1: | |
filename = input('Input filename to save/load events: ') | |
else: | |
filename = sys.argv[1] | |
if os.path.exists(filename): | |
segments = pickle.load(open(filename, 'rb')) | |
for i, segment in enumerate(segments): | |
print('Press F1 to play segment {}/{}'.format(i+1, len(segments))) | |
print('Duration: {} seconds'.format(segment[-1].time - segment[0].time)) | |
keyboard.wait('F1') | |
keyboard.play(segment) | |
else: | |
print('Press F1 to save this fragment. Press F2 to discard it. Press ESC twice to finish.') | |
segments = [] | |
segment = [] | |
def handle_event(event): | |
global segment | |
if event.matches('F1'): | |
if event.event_type == keyboard.KEY_DOWN: | |
if segment: | |
segments.append(segment) | |
segment = [] | |
print('Saved', len(segments)) | |
elif event.matches('F2'): | |
if event.event_type == keyboard.KEY_DOWN: | |
segment = [] | |
print('Discarded') | |
else: | |
segment.append(event) | |
keyboard.listener.add_handler(handle_event) | |
keyboard.wait('esc, esc') | |
keyboard.listener.remove_handler(handle_event) | |
pickle.dump(segments, open(filename, 'wb')) | |
print('Saved {} segments to {}'.format(len(segments), filename)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
When recording, press F1 to save the current segment, F2 to discard it, and press ESC twice to finish. Give an existing file to play back saved segments.
Requires
pip install keyboard
.