检测诅咒中的自动按键重复
我正在Linux 上使用curses 编写一个小型文本模式应用程序。
对于键盘输入,我使用curses 函数。按键自动重复工作,例如,如果我按住一个键,我会收到多个按键事件,直到我再次释放该键。
是否也可以区分真实的按键事件和按键重复逻辑生成的事件?
背景:该应用程序是一个小型数据输入前端,用户可以在其中修改某些参数的整数。从长远来看,该应用程序无需标准键盘即可运行。我只有四个用于数据输入的按钮:“增加”、“减少”、“确定”和“取消”。
由于数字范围很大,我想知道用户是否按住了某个键。如果他这样做,我可以更快地扫描我的数字范围,而不是将我的数字增加 1,而是增加 10 或可能 100。如果用户 otoh 轻击该键,输入方法应该再次精确,只需将数字增加/减少 1。
可以用curses的键盘输入功能实现吗?
I'm writing a little text mode application using curses on Linux.
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'.
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.
Is this possible with the keyboard input functions of curses?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不 - 诅咒只接收来自终端的密钥。如果您确实需要它,您可以尝试通过查看每次按键之间的延迟来确定按键重复是否是自动的。但是,特别是通过远程连接,这可能不是一个好的解决方案,因为延迟会受到网络延迟的影响。
最好的解决方案可能是使用 UP/DOWN 进行小步骤,使用 PAGEUP/PAGEDOWN 进行大步骤。
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.
The best solution might be using UP/DOWN for small steps and PAGEUP/PAGEDOWN for large steps.