11
submitted 1 year ago* (last edited 1 year ago) by prettydarknwild@lemmy.world to c/python@programming.dev

im creating an application using curses and im using the getch() function to get keyboard input, the problem is, that it is painfully slow, it takes several seconds to detect the pressed key and normally i have to press the key several times so the program actually detects it, there is a way to make getch() respond instantly (or at least at a usable speed)?

top 4 comments
sorted by: hot top controversial new old
[-] Shimitar@feddit.it 6 points 1 year ago

I believe you are using it wrong. I assume Linux ofc.

You need to poll/wait on it, and it is immediate and never loses one press if you use it properly.

Otherwise look into raw mode, you will need to change the input mode and will be able to read keypresses "as in videogames".

If you need I can point you to some code, bit since you didn't post any I assume you want to do it by yourself

[-] prettydarknwild@lemmy.world 1 points 1 year ago

the problem was that that i was evaluating the output of getch() in every if statement inside my main loop instead of defining it as a variable inside the loop and checking that variable

[-] MinekPo1@lemmygrad.ml 2 points 1 year ago

just gonna add that if you are using curses just for the getch function, I recommend the getch module from pip

[-] FooBarrington@lemmy.world 1 points 1 year ago

Can you share a small reproduction example?

this post was submitted on 02 Sep 2023
11 points (86.7% liked)

Python

6287 readers
3 users here now

Welcome to the Python community on the programming.dev Lemmy instance!

📅 Events

PastNovember 2023

October 2023

July 2023

August 2023

September 2023

🐍 Python project:
💓 Python Community:
✨ Python Ecosystem:
🌌 Fediverse
Communities
Projects
Feeds

founded 1 year ago
MODERATORS