From a401632a210413c3a4f0237c8fd8986bdf45934c Mon Sep 17 00:00:00 2001 From: Mischa POSLAWSKY Date: Sat, 21 Mar 2009 02:41:12 +0000 Subject: [PATCH] browser keypress selects page key Javascript onkeypress handler which marks and clicks on a matching key if it is pressed in the browser. Increases Vim page size by 11kB (approx 10%) because each key requires a class name for unambiguous character identification. With gzip compression the difference is just 1422 bytes (though still 10%), so assume this is (or at least will be) a worthwhile trade-off. --- Shiar_Sheet/Keyboard.pm | 3 ++- keys.js | 27 +++++++++++++++++++++++++++ nethack.plp | 2 +- vim.plp | 2 +- vimperator.plp | 2 +- 5 files changed, 32 insertions(+), 4 deletions(-) diff --git a/Shiar_Sheet/Keyboard.pm b/Shiar_Sheet/Keyboard.pm index 58d7da2..9456b7d 100644 --- a/Shiar_Sheet/Keyboard.pm +++ b/Shiar_Sheet/Keyboard.pm @@ -5,7 +5,7 @@ use warnings; no warnings 'uninitialized'; # save some useless checks for more legible code use Carp; -our $VERSION = '1.02'; +our $VERSION = '1.03'; my @casedesc = (undef, qw/shift ctrl meta/, 'shift meta'); my @rowdesc = qw(numeric top home bottom); @@ -97,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
  • $keytxt}; print ' ', $desc if defined $desc; diff --git a/keys.js b/keys.js index d891b52..5dbfb10 100644 --- a/keys.js +++ b/keys.js @@ -23,3 +23,30 @@ function setmode(classname) { } } +var keyfocus = undefined; +document.onkeypress = function(e) { + var keylabels = document.getElementById('rows').getElementsByTagName('B'); + var keys = {}; + for (var i = 0; i < keylabels.length; i++) { + keys[keylabels[i].innerHTML] = keylabels[i].parentNode; + } + var input = e.charCode || e.keyCode; + for (var i = 0; i < keylabels.length; i++) { + var key = keylabels[i].parentNode; + var keychar = key.className.match(/ chr(\d+)$/); + if (!keychar) continue; // not enterable + keychar = keychar[1]; + if (keychar != input) continue; // different key + var keymod = key.parentNode.className; + if ((keymod.search(/\bctrl\b/) != -1) != e.ctrlKey) continue; // modifier mismatch + if ((keymod.search(/\bmeta\b/) != -1) != e.altKey) continue; + var row = key.parentNode.parentNode; + var shown = row.style.display != 'none'; + if (!shown) continue; // foreign mode + if (keyfocus) keyfocus.style.outline = ''; + key.style.outline = '1px solid red'; + keyfocus = key; + if (key.onclick) key.onclick(); + return false; + } +} diff --git a/nethack.plp b/nethack.plp index dc8e616..b6f8a4a 100644 --- a/nethack.plp +++ b/nethack.plp @@ -44,7 +44,7 @@ $header{content_type} = "text/html; charset=$sign{charset}";
  • diff --git a/vim.plp b/vim.plp index b8a1f5c..af74074 100644 --- a/vim.plp +++ b/vim.plp @@ -44,7 +44,7 @@ $header{content_type} = "text/html; charset=$sign{charset}";
  • diff --git a/vimperator.plp b/vimperator.plp index cdde680..19298d1 100644 --- a/vimperator.plp +++ b/vimperator.plp @@ -44,7 +44,7 @@ $header{content_type} = "text/html; charset=$sign{charset}";
  • -- 2.30.0