From 9b1657646b36d904fbe5dbac57546385f8852416 Mon Sep 17 00:00:00 2001 From: Macoy Madson Date: Sun, 2 Jul 2017 09:38:28 -0700 Subject: [PATCH] Added hacky Curses-based keyboard input test Polling for keypresses in python is a PITA. I also added a convenience build system that will probably only work for me --- project/keykey.sublime-project | 13 ++++++++++--- sequencer.py | 24 ++++++++++++++++++++++-- 2 files changed, 32 insertions(+), 5 deletions(-) diff --git a/project/keykey.sublime-project b/project/keykey.sublime-project index 7e14f43..fdfd257 100644 --- a/project/keykey.sublime-project +++ b/project/keykey.sublime-project @@ -10,15 +10,22 @@ ], "build_systems": [ - // For galavant/, use - // "working_dir": "$project_path/../../.." + // For keykey/, use + // "working_dir": "$project_path/.." // Not sure why, but Sublime will actually keep going up across builds if you just do ../ first + //guake -n MyTabName -e "command args" + { + "name": "Sequencer Run", + "shell_cmd": "guake -n KeyKey -e \"(cd Development/code/repositories/keykey && exec python3 -c 'import sequencer; sequencer.main()')\"", + "working_dir": "$project_path/.." + }, + // Misc. Commands { "name": "List", "shell_cmd": "ls -l", - "working_dir": "$project_path" + "working_dir": "$project_path/.." }, ] } diff --git a/sequencer.py b/sequencer.py index f09e3ec..2b5e21e 100644 --- a/sequencer.py +++ b/sequencer.py @@ -1,5 +1,6 @@ import mido import time +import curses """ mido.get_input_names() @@ -169,7 +170,26 @@ def simpleSequencer(): http://mido.readthedocs.io/en/latest/ports.html?highlight=reset """ # synthOut.panic() -if __name__ == '__main__': +# Note that key repeats mean that key holding is fucking weird +def testKeyInput(stdscr): + # Make getch() nonblocking + stdscr.nodelay(1) + while True: + inputChar = stdscr.getch() + if inputChar == ord('f'): + stdscr.addstr("This is a test") + elif inputChar == ord('q'): + break + + time.sleep(0.05) + +def main(): # testOutput() # testIO() - simpleSequencer() + # Put in curses.wrapper so that the curses shit is cleaned up on close/exception + curses.wrapper(testKeyInput) + + #simpleSequencer() + +if __name__ == '__main__': + main() \ No newline at end of file