Suppose I want to make a very simple program in python that shows how long a key has been pressed. Therefore, if I type and hold the j key for several seconds, I am looking to write a program that can display information like the key 'j' was pressed for 1.1 seconds .
From what I understand, the way this needs to be achieved is to detect and temporarily bind KEYDOWN events and KEYUP events and create the appropriate deductions for timestamps. Thus, it would be sufficient to detect the KEYDOWN and KEYUP events.
There are many different questions and answers to SO about detecting a single keystroke or about detecting a single character input, such as this or this one that uses some form of getch. I looked at the curses python library, and from what I can tell, the primary form of key detection is also presented as a single-character getch (). But they do not detect the length of the keystroke - they only detect KEYDOWN.
I understand that determining the length of a keystroke is a necessary task in games, and therefore I expect pygame to have methods for detecting the length of a keystroke. But I hope that you can use a much thinner and more direct library to detect the duration of a keystroke.
source share