【问题标题】:What does it mean, when Term::ReadKey::ReadKey returns "0"?当 Term::ReadKey::ReadKey 返回“0”时,这是什么意思?
【发布时间】:2013-04-11 12:50:02
【问题描述】:

在 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
这个 null 是否意味着它是 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

【问题讨论】:

    标签: perl getc readkey


    【解决方案1】:

    showkey -a 给我看

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

    并且在this 的回答中说 CtrlSpace 发送 ASCII NUL 所以我假设 0 代表 Ctrl空格 1 代表 Ctrla

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-04-20
      • 1970-01-01
      • 2013-11-19
      • 2014-02-03
      • 1970-01-01
      相关资源
      最近更新 更多