When a keyboard event is for us (when this script does something), stop it from
propagating to other event handlers.
-// This is activated (and canceled) by pressing the `/~ key. To change it to a
-// differet key, edit the ascii value on line 301
-//
-// Also, you can change the character set a few lines down. Don't use the "L"
-// key unless you change the on line 235.
-
-
+// This is activated (and canceled) by pressing the ^C
+// Press L (first) to switch to one-hand mode
+
+// I was getting some very funky return values from String.fromCharCode() for
+// punctuation keys so I made my own table. You might need to change this for
+// your computer/keyboard. You'll need to have every character in "charset" in
+// here.
+
+var key_to_char = {
+ '84': 't',
+ '72': 'h',
+ '83': 's',
+ '78': 'n',
+ '68': 'd',
+ '189': '-',
+ '82': 'r',
+ '67': 'c',
+ '71': 'g',
+ '77': 'm',
+ '86': 'v',
+ '87': 'w',
+ '66': 'b',
+ '191': '/',
+ '186': ';',
+ '55': '7',
+ '56': '8',
+ '57': '9',
+ '65': 'a',
+ '69': 'e',
+ '70': 'f',
+ '73': 'i',
+ '74': 'j',
+ '75': 'k',
+ '79': 'o',
+ '80': 'p',
+ '81': 'q',
+ '85': 'u',
+ '88': 'x',
+ '89': 'y',
+ '90': 'z',
+ '50': '2',
+ '51': '3',
+ '52': '4',
+ '222': "'",
+ '76': 'l' // switch to one-hand mode
+}
//Just some shortcuts and globals
//Just some shortcuts and globals
-var charset = 'thsnd-rcgmvwb/;789aefijkopquxyz234';
+var charset = 'thsnd-rcgmvwb/;789aefijkopquxyz234'; // update key_to_char if you add to this
var uzblid = 'uzbl_link_hint';
var uzbldivid = uzblid + '_div_container';
var doc = document;
var uzblid = 'uzbl_link_hint';
var uzbldivid = uzblid + '_div_container';
var doc = document;
+ // from your event handler you can: return stop_event(e)
+ function stop_event(e) {
+ // try {
+ e.stopPropagation();
+ e.preventDefault();
+ // } catch (ex) {
+ // return false; // IE-compat
+ // }
+ }
var active = 0;
var got = '';
document.addEventListener(
var active = 0;
var got = '';
document.addEventListener(
- if(e.keyCode == 96) { // change this if you want a different activation key
+ // [de]activate on ^C
+ // deactivate on ESC
+ if(
+ (e.ctrlKey && e.keyCode == 67)
+ || (e.keyCode == 27 && active == 1)
+ ) {
if(active) {
got = '';
removeAllHints();
if(active) {
got = '';
removeAllHints();
followLinks(got);
}
active = 1 - active;
followLinks(got);
}
active = 1 - active;
- if(active == 1) {
- got += String.fromCharCode(e.keyCode);
- followLinks(got);
+ if(active == 1 && !e.ctrlKey && !e.shiftKey && !e.altKey) {
+ if(key_to_char[e.keyCode]) {
+ got += key_to_char[e.keyCode];
+ followLinks(got);
+ return stop_event(e);
+ }