检测诅咒中的自动按键重复

发布于 2024-10-02 10:53:03 字数 403 浏览 1 评论 0原文

我正在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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

时光沙漏 2024-10-09 10:53:03

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

最好的解决方案可能是使用 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文