Detect automatic key repeats in curses

I am writing a small text application using curses on Linux.

I use the curses functions to enter the keyboard. Key auto-retries work, for example. if I hold the key down, I get a few key events until I release the key again.

Is it also possible to distinguish between real-key events and those generated by the key repetition logic?

Background: the application is a small data entry interface in which the user can change integers of certain parameters. Ultimately, the application will work without a standard keyboard. I will have only four buttons for entering data: “increase”, “decrease”, “ok” and “cancel”.

Since the ranges of numbers are large, I would like to know if the user holds the key. If he does, I can quickly scan my number range without increasing my number by one, but by 10 or maybe 100. If the user wears out the key, the input method should be accurate again and just increase / decrease the numbers by one.

Is this possible with cursive keyboard input functions?

+1
source share
1 answer

No - curses just get the keys to the terminal. If you really need it, you can try to find out whether automatic repeats are automatic or not, if you look at the delay between each keystroke. However, especially with regard to remote connections, this may not be the best solution, since the delay will depend on the network delay.

A better solution would be to use UP / DOWN for small steps and PAGEUP / PAGEDOWN for large steps.

+2
source

Source: https://habr.com/ru/post/1402798/


All Articles