ncurses捕获扩展键(向左控制,Shift-Shift等) [英] ncurses trapping extended keys (Control-left, Shift-Function etc)

查看:119
本文介绍了ncurses捕获扩展键(向左控制,Shift-Shift等)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在我的红宝石程序中捕获Control-Left,Shift-F10等.通常,仅使用getch即可获得有效的整数列表,例如27,91,50,50,126.但是我担心这些可能与系统或终端有关.谷歌搜索之后,我发现了有关use_extended_names,tigetstr等的内容.我找到了一个使用它们的C程序,该程序在运行时发现键码(由Thomas Dickey撰写).我运行它,似乎发现了扩展键,但是在同一程序中的getch仍然为我提供了通常的整数列表,例如[27,91,53,68],无论如何我都得到了C-left.我希望得到一个返回值,它所提到的那个.

I am trying to trap Control-Left, Shift-F10 etc in my ruby programs. Normally, using just getch I get a list of ints such as 27,91,50,50,126 which works. However I fear these may be system or terminal dependent. After googling I found about use_extended_names, tigetstr etc. I found a C program using these which discovers the keycodes at run time (by Thomas Dickey). I run it and it seems to discover extended keys, but then the getch in the same program still gives me the usual list of ints such as [27,91,53,68] for C-left which I am getting anyway. I expect to get one return value, the one it mentions.

我想念什么?

这是我按Control-left时的输出:

Here is the output when I press Control-left:

keypress=27
keypress=91
keypress=53
keypress=68
key=kLFT5, code=540
key=kEND5, code=525
key=kHOM5, code=530
key=kHOM3, code=528
key=kUP5, code=561
key=kDN5, code=520

我不能只得到540吗?

Should I not get just 540 ?

这里是keytest.c: https://gist.github.com/1237091

Here is keytest.c : https://gist.github.com/1237091

奇怪的是,在TERM = screen下运行时,所有代码都显示为0.上面是TERM = xterm. (我在OSX上使用Terminal)

Strangely, all the codes show 0 when running under TERM=screen. The above is TERM=xterm. (I am on OSX using Terminal)

推荐答案

诅咒是在人们真正在终端中进行修饰符之前设计的.其键处理模型实际上是值的平面枚举,并且不容易处理任意键+修饰符组合.

Curses was designed at a time before people were really doing modifiers in terminals. Its key handling model is effectively a flat enumeration of values, and doesn't easily handle arbitrary key + modifier combinations.

为了更好地解决这个问题,我写了libtermkey,改用它可能会让您更幸运.

To solve this better, I wrote libtermkey, you may be more luck using this instead.

http://www.leonerd.org.uk/code/libtermkey/

这是一个C库,尽管它同时具有Perl和Python绑定.我以为有人也应该能够很容易地为其构建一些Ruby绑定.

It's a C library, though it has both Perl and Python bindings. I'd imagine someone ought to be able to build some Ruby bindings quite easily for it as well.

这篇关于ncurses捕获扩展键(向左控制,Shift-Shift等)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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