如何获得Ctrl,Shift或Alt键与残培()ncurses的? [英] How to get CTRL, Shift or Alt with getch() ncurses?
问题描述
所有在这个问题吗?如何获得Ctrl,Shift键或Alt键的getch()ncurses的?结果
我无法得到它的工作得到Ctrl,Shift或Alt键用的ncurses的getch()?我怀念的东西在男人?
All is in the question ? How to get CTRL, Shift or Alt with getch() ncurses ?
I cannot get it work to get CTRL, Shift or Alt with getch() using ncurses ? Do I miss something in the man ?
推荐答案
正确的答案被多么惊人有时降级,并回答说:权威性放弃升职......随着创造力位,KEY_NAME实际持有权关键弄清这一点,只有一条 - 那SHIFT / ALT / CTRL是在同一时间与其他键pssed $ p $:
Amazing how sometimes the right answer gets demoted, and answers that "authoritatively" give up get promoted... With a bit of creativity, key_name actually holds the right key to figuring this out, with one caveat - that SHIFT/ALT/CTRL are pressed with other keys at the same time:
-
首先,对于普通键,如打印的人,你可以很容易地检测转变,因为它uppercases。
First, for "normal keys" such as the printable ones, you can easily detect shift because it uppercases.
有关特殊键,例如KEY_LEFT,你会看到,当SHIFT选择实际上是KEY_SLEFT产生的code。同上,用于KEY_RIGHT。不幸的是,没有这样的运气KEY_UP / KEY_DOWN,它通过SHIFT似乎未受影响。所以,你可以通过函数getch()返回的字符区分 - 在KEY_S ..意味着转变是pressed
For special keys, e.g. KEY_LEFT, you will see that the code generated when SHIFT is selected is actually KEY_SLEFT. ditto for KEY_RIGHT. Unfortunately, no such luck for KEY_UP/KEY_DOWN , which seem unfazed by SHIFT. So you can distinguish by the returned char from getch() - the KEY_S.. implies shift was pressed.
有关ALT(有什么不被困X或水族窗口管理器,至少),注册表将密钥转换为一个M ...什么的。
For ALT (what's not trapped by X or the Aqua Windowmanager, at least), keyname will convert the key to an M... something.
有关CTRL你会得到一个^preceding实际的键名。例如^ R键为18
For CTRL you'll get a "^" preceding the actual key name. E.g ^R for key 18
所以,你现在可以计算出密钥codeS为交换机(残培)语句等,通过简单的片断:
So you can now figure out the key codes for your switch(getch) statements, etc, by a simple snippet:
ch = getch(); endwin(); printf("KEY NAME : %s - %d\n", keyname(ch),ch);
,就是这样。明确地说不能想想之前。也许有这是不太明显的方式。
and that's that. Think before definitively saying "can't". Maybe there's a way that's less obvious.
这篇关于如何获得Ctrl,Shift或Alt键与残培()ncurses的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!