Learn to Code via Tutorials on Repl.it!

← Back to all posts
@Reuben123's Python Keypress Detection - The Basic Tutorial
Reuben123 (29)

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

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:

https://repl.it/talk/share/Arrow-keys-and-such-using-from-readchar-import-readkey/28853?order=votes

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

Comments
hotnewtop
aprillsavells (2)

is it posible to detect clicks?

???

adl212 (175)

@Reuben123 this is a great tutorial and is really helpful. Thanks!

coderash (290)

omg thx, i need this for a project im working on :D

Reuben123 (29)

@coderash Good timing then! Glad I could help :D Gave you a cycle.

Reuben123 (29)

@coderash No problem. Hope all goes well with your project. If you need some help, even though I'm not the best, I could help you out or create another tutorial :)

coderash (290)

Haha yeah, know anything about django xD im building a form-making [email protected]

Reuben123 (29)

@coderash Sound great :) I would have to do some learning lol

aprillsavells (2)

@Reuben123 is it possible to detect clicks ??

Legendthecoder (0)

@Reuben123 Hey it works very good!, Can you please explain to me how it works?

INCOGNITO001 (15)

@Reuben123 Other people seem not to be having trouble with this tutorial, but for me it says there is no module called readchar.
Do you have any idea why this might be? I ran your example program and it gave me exactly the same error.

LucasLum (4)

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

DominicHuieWhit (52)

as a n00b this is amazing