Pergunta

With dumpkeys --long-info called in a Linux-Terminal I get these values:

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

When I run this script and press Ctrl a or Ctrl b I get the corresponding values.
When I press Ctrl Space ReadKey returns 0.
Does this null mean it is the value of Ctrl Space or does it mean there is something not set or empty?

#!/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
Foi útil?

Solução

showkey -a shows me

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

and in this answer is said that CtrlSpace sends ASCII NUL so I'm assuming 0 is for CtrlSpace what 1 is for Ctrla

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top