On Tue, Jul 4, 2017 at 8:50 AM, Carlton Banks <nofl...@gmail.com> wrote: > I am using pynput <https://pypi.python.org/pypi/pynput> for keyboard events
You could use an event that enables a recording loop. The on_press and on_release callbacks of the Listener [1] would set() and clear() this event, respectively. For example: import threading from pynput import keyboard def main(): do_record = threading.Event() def on_press(key): if key == keyboard.Key.cmd_l: do_record.set() def on_release(key): if key == keyboard.Key.cmd_l: do_record.clear() with keyboard.Listener(on_press=on_press, on_release=on_release) as listener: do_record.wait() frames = [] while do_record.is_set(): print('Started recording') # record and append audio frame print('Stopped recording') listener.join() [1]: http://pythonhosted.org/pynput/keyboard.html#pynput.keyboard.Listener _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor