如何阅读Bash中任意一键? [英] How do I read any one key in Bash?
问题描述
我能获得读-n 1键
来获得最关键的,除了这是通过重新多个字符psented $ P $键。例如,如果我preSS向上箭头键:
$读-n 1;回声
^ [[A
$ [A
正如你所看到的,读
只需要在<大骨节病> ESC 骨节病>和 [A
剩下的。
我希望能够在脚本做的是:
- 通过列表,请使用箭头键和preSS <大骨节病>输入骨节病>以用它做什么
- 对于其他操作,preSS不同的密钥。
您最好使用提到的对话框,jm666,但也有其他的方式来皮肤猫。
读-n 1个;而读-n 1 -t .1ÿ;做X =$ X $ Y; DONE
基本上等到你读一个字符,然后旋转消费输入直到0.1秒已通过W / O输入。
警告,快速打字员可能会感到恼火。您可能需要调整的超时时间。
I can get read -n 1 KEY
to get most keys, except for keys which are represented by multiple characters. For example, if I press the up arrow key:
$ read -n 1; echo
^[[A
$ [A
As you can see, read
only takes the Esc and the [A
is left over.
What I want to be able to do in a script is:
- Go through a list with the arrow keys and press Enter to do something with it
- For other actions, press different keys.
You are better off using dialog as jm666 mentioned, but there are other ways to skin that cat.
read -n 1 x; while read -n 1 -t .1 y; do x="$x$y"; done
Basically wait until you read a character and then spin consuming input until .1 seconds has passed w/o input.
Warning, fast typists could get annoyed. You might need to tweak that timeout.
这篇关于如何阅读Bash中任意一键?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!