browser keypress selects page key
[sheet.git] / Shiar_Sheet / Keyboard.pm
index d8d827440b474d88a68d680028ad95a682dd815f..9456b7d1f212b5c47f787125fead8a62bc557e50 100644 (file)
@@ -5,11 +5,13 @@ use warnings;
 no  warnings 'uninitialized';  # save some useless checks for more legible code
 use Carp;
 
-our $VERSION = '1.01';
+our $VERSION = '1.03';
 
-my @casedesc = qw(ctrl shift);
+my @casedesc = (undef, qw/shift ctrl meta/, 'shift meta');
 my @rowdesc = qw(numeric top home bottom);
 my %keyrows = do 'keys.inc.pl';
+# add first two cases of each row again with each char prepended by + (alt)
+push @$_, map { [map {"+$_"} @$_] } @$_[0,1] for map {@$_} values %keyrows;
 
 my %keytrans = qw(
        ^@ NUL ^a SOH ^b STX ^c ETX  ^d EOT ^e ENQ ^f ACK ^g BEL
@@ -45,6 +47,7 @@ sub map {
 sub escapeclass {
        local $_ = shift;
        s/\^/_c/g;
+       s/\+/_m/g;
        s/\[/_sbo/g;
        s/\]/_sbc/g;
        s/^$/_/;
@@ -63,7 +66,7 @@ sub keyunalias {
        my $self = shift;
        my ($key, $ancestry) = @_;
 
-       $key =~ s/(\S*?)(\^?\S)($|\s.*)/$2/;
+       $key =~ s/(\S*?)(\+?\^?\S)($|\s.*)/$2/;
        my $mode = $1;
        my $keyinfo = $self->{keys}->{$mode}->{$key};
 
@@ -94,6 +97,7 @@ sub print_key {
        $onclick .= sprintf(q{ onclick="document.location='%s'"}, $1)
                if $flags =~ s/ ?\blink(\S*)//;
        my $keyhint = defined($mnem) && qq{ title="$mnem"};
+       $flags .= ' chr'.ord(substr $key, -1) if $key ne '^0';
 
        print qq{\t\t<li class="$flags"$onclick><b$keyhint>$keytxt</b>};
        print ' ', $desc if defined $desc;
@@ -107,13 +111,12 @@ sub print_rows {
 
        for (my $row = 0; $row <= $#{ $keyrows{$self->{map}} }; $row++) {
                my $keyrow = $keyrows{$self->{map}}->[$row];
-               my @caserows = 0 .. $#$keyrow;
 
                print qq{<li class="row row$row"><ul>\n};
                for my $modefull (@moderows) {
                        my $mode = $modefull;
                        my @showcase = $mode =~ s/(\d+)(?:-(\d+))?$//
-                               ? (map {3 - $_} split //, $row == 0 && $2 || $1) : @caserows;
+                               ? (map {$_ - 1} split //, $row == 0 && $2 || $1) : (2, 1, 0);
                        my $modekeys = $self->{keys}{$mode};
 
                        for my $case (@showcase) {