当Term :: ReadKey :: ReadKey返回“0”时,它是什么意思?

时间:2013-04-18 12:01:11

标签: perl getc readkey

在Linux终端中调用dumpkeys --long-info我得到以下值:

# ...
0x0000  nul
0x0001  Control_a
0x0002  Control_b
0x0003  Control_c
0x0004  Control_d
# ...

当我运行此脚本并按Ctrl aCtrl b时,我会得到相应的值 当我按Ctrl Space ReadKey时,会返回0 这是否意味着它是Ctrl Space的值,或者它是否意味着没有设置或为空?

#!/usr/bin/env perl
use warnings;
use strict;
use Term::ReadKey;

ReadMode('cbreak');
print "Press keys to see their ASCII values.  Use Ctrl-C to quit.\n";

while (1) {
    my $char = ReadKey(0);
    last unless defined $char;
    printf("$char -> Hex: %x\n", ord($char), ord($char));
}

ReadMode('normal');

# -> Hex: 1  # Ctrl a
# -> Hex: 2  # Ctrl b
# -> Hex: 4  # Ctrl d
# -> Hex: 0  # Ctrl Space

1 个答案:

答案 0 :(得分:0)

showkey -a告诉我

^A        1 0001 0x01   #  Ctrl a
^B        2 0002 0x02   #  Ctrl b
^@        0 0000 0x00   #  Ctrl Space

并在this回答说 Ctrl Space 发送ASCII NUL所以我假设0代表 Ctrl < kbd> Space Ctrl a