Skip to content

Instantly share code, notes, and snippets.

@jdthorpe
Created July 8, 2020 16:38
Show Gist options
  • Save jdthorpe/25d6c93eb20c1171daba011c582e675f to your computer and use it in GitHub Desktop.
Save jdthorpe/25d6c93eb20c1171daba011c582e675f to your computer and use it in GitHub Desktop.
Python Lessons
import msvcrt
# Binary codes for escape and control+C
ESCAPE = b'\x1b'
COTNROL_C = b'\x03'
RGB = [0,0,0]
while True:
# GET A SINGLE CHARACTER FROM THE USER
# (returned as a binary value)
char = msvcrt.getch()
# ALLOW THE USER TO BREAK OUT OF THE LOOP
if char in (ESCAPE, COTNROL_C) :
break
# DO SOME THINGS
if char == b'1':
RGB[0] = 1 - RGB[0]
elif char == b'2':
RGB[1] = 1 - RGB[1]
elif char == b'3':
RGB[2] = 1 - RGB[2]
# PRINT THE RESULT
# (Note that end='\r' moves the cursor to the start of the
# current line instead of the start of the next line
print(RGB, end='\r')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment