检测诅咒中的自动按键重复 [英] detect automatic key-repeats in curses

查看:94
本文介绍了检测诅咒中的自动按键重复的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Linux上的curses编写一个文本模式的小程序.

I'm writing a little text mode application using curses on Linux.

对于键盘输入,我使用curses功能.按键自动重复功能,例如如果我按住某个键,则会收到多个键事件,直到再次释放该键为止.

For keyboard input I use the curses functions. Key auto-repeats work, e.g. if I hold a key down I get multiple key events until I release the key again.

是否还可以区分真实按键事件和按键重复逻辑生成的按键事件?

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

背景:该应用程序是一个小的数据输入前端,用户可以在其中修改某些参数的整数.从长远来看,该应用程序无需使用标准键盘即可运行.我只有四个用于输入数据的按钮:增加",减少",确定"和取消".

Background: The application is a little data-entry front-end where the user can modify integer numbers of certain parameters. In the long run the application will work without a standard keyboard. I will only have four buttons for data-entry: 'increase', 'decrease', 'ok' and 'cancel'.

由于数字范围很大,所以我想知道用户是否按住了一个键.如果他这样做了,我可以通过不将数字加1而是加10或也许加100来在数字范围内更快地扫描.如果用户otoh轻按了该键,则输入方法应该再次精确,并且只需将数字增加/减小一即可.

Since the number ranges are large I'd like to know if the user holds down a key. If he does so I can scan faster through my numeric range by not incrementing my number by one but by 10 or maybe 100. If the user otoh taps the key the input method should be precise again and just increase/decrease the numbers by one.

使用curses的键盘输入功能可以吗?

Is this possible with the keyboard input functions of curses?

推荐答案

否-curses只是从终端接收密钥.如果您确实需要它,可以通过查看每次按键之间的延迟来尝试来找出按键重复是否是自动的.但是,尤其是在远程连接上,这可能不是一个好的解决方案,因为延迟会受到网络延迟的影响.

No - curses just receives keys from the terminal. If you really need it you could try to find out if the key repeats are automated or not by looking at the delay between each keypress. However, especially over remote connections, this might not be a good solution as the delay will be affected by network latency.

最好的解决方案可能是对小步使用UP/DOWN,对大步使用PAGEUP/PAGEDOWN.

The best solution might be using UP/DOWN for small steps and PAGEUP/PAGEDOWN for large steps.

这篇关于检测诅咒中的自动按键重复的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆