Thread [CTRL] Taste einlesen: Tastatur (19 answers)
Opened by romulus at 2004-05-24 19:15

pq
 2004-06-01 04:46
#82693 #82693
User since
2003-08-04
12209 Artikel
Admin1
[Homepage]
user image
hab mal ein programm gebastelt, welche die key-codes für eingetippte zeichen anzeigt. leider funktioniert es auch nicht bei allen tasten-kombination, z.B. ist CTRL-TAB identisch mit TAB, aber hier mal das programm:
Code: (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/perl -w
use strict;
use Term::ReadKey;
my $key;
print "Stop with CTRL-C\n";
unless (@ARGV) {
 print "Please enter your key:";
 $key = get_key();
}
else {
 $key = shift;
}
if (ref $key) {
 # got more than one key
 print "\nKeys:\n";
 print "$_\n" for map {ord $_} @$key;
}
else {
 my $ord = ord $key;
 print <<EOM;

Pressed: ($key)
Ord:      $ord        
EOM
}
sub get_key {
 my $key;
 ReadMode 4; # Turn off controls keys
 while (not defined ($key = ReadKey(-1))) {
 # No key yet
 }
 my $ord = ord $key;
 (ReadMode 0), exit if $ord == 3; # STRG-C
 ReadMode 0;
 if ($ord == 27) {
   my @keys = $key;
   while (defined(my $k = get_key_nb())) {
     push @keys, $k;
   }
   return \@keys;
 }
 return $key;
}
sub get_key_nb {
 ReadMode 4; # Turn off controls keys
 my $key = ReadKey(-1) or (ReadMode 0),return;
 my $ord = ord $key;
 (ReadMode 0), exit if $ord == 3; # STRG-C
 ReadMode 0;
 return $key;
}
Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live. -- Damian Conway in "Perl Best Practices"
lesen: Wiki:Wie frage ich & perlintro Wiki:brian's Leitfaden für jedes Perl-Problem

View full thread [CTRL] Taste einlesen: Tastatur