@Reuben123's Python Keypress Detection - The Basic Tutorial
Reuben123 (26)

Hello fellow programmers,

Here is my tutorial for key detection in python!
Using readchar, we can detect and interpret key presses in python, without having to press enter after key presses.

I have created a demo / example project demonstrating this. Below is also a step by step guide for how you can do this too.

Here's how:

1) Importing readchar
from readchar import readchar

2) Creating your variable
your_variable_here = readchar()

3) Input and keypress functions

if your_variable_here == '1':
   #1 - First Keypress
   print("Hello, World!")
elif your_variable_here == '2':
   #2 - Second Keypress 
   print("Your Awesome!")
   #If input != '1' OR '2'
   print("Invalid Input")

That's it.

These are the basics, you can add more functions and change what you want. This was just meant to be a simple guide to get you started.

If you would like to see a slightly more complex example of this see @52eagle's post:


If you need further help or have any suggestions, feel free to put them in the comments. I'll be giving everyone cycles :)

I'm quite new to python too so feel free to give me any tips or advice that could help me improve.

All the best and hope this helps 👍

by @Reuben123

You are viewing a single comment. View All
LucasLum (4)

Just wondering, is there a way to detect this in Python Turtle?