diff options
author | Tom Feist <shabble@cowu.be> | 2010-07-24 16:35:43 +0000 |
---|---|---|
committer | Tom Feist <shabble@cowu.be> | 2010-07-24 16:35:43 +0000 |
commit | 501309887a7499b91c2b9fa8f76180c2738d7990 (patch) | |
tree | 5bc5f26da277c8b4c7d66c5863ba365723dc6c53 /history-search/key_test.pl | |
parent | misc stuffs (diff) | |
download | irssi-scripts-501309887a7499b91c2b9fa8f76180c2738d7990.tar.gz irssi-scripts-501309887a7499b91c2b9fa8f76180c2738d7990.zip |
something confusing going on here, have I got nested repos?
Diffstat (limited to 'history-search/key_test.pl')
-rw-r--r-- | history-search/key_test.pl | 100 |
1 files changed, 100 insertions, 0 deletions
diff --git a/history-search/key_test.pl b/history-search/key_test.pl new file mode 100644 index 0000000..b16ff00 --- /dev/null +++ b/history-search/key_test.pl @@ -0,0 +1,100 @@ +use strict; +use Irssi; +use Irssi::TextUI; # for sbar_items_redraw + +use vars qw($VERSION %IRSSI); +$VERSION = "1.0.1"; +%IRSSI = ( + authors => "shabble", + contact => 'shabble+irssi@metavore.org, shabble@#irssi/Freenode', + name => "", + description => "", + license => "Public Domain", + changed => "" +); + + +Irssi::signal_add_last 'gui key pressed' => \&got_key; + +my $buf = ''; + +sub got_key { + my ($key) = @_; + $buf .= " $key"; + my $res = decode_keypress($key); + if (defined $res) { + print "codes: $buf"; + print "Keypress: $res"; + $buf = ''; + } +} + +# 1 means we've seen an esc, 2 means we've +# seen an esc,[. 0 is normal. + +my $decoder_state = 0; + +sub decode_keypress { + my ($code) = @_; + + if ($decoder_state == 1) { + + # seen esc/meta. + if ($code == ord('[')) { + $decoder_state = 2; + return undef; + } else { + $decoder_state = 0; + return 'meta-' . chr($code); + } + + } elsif ($decoder_state == 2) { + + if ($code == ord('A')) { + $decoder_state = 0; + return 'up-arrow'; + } elsif ($code == ord('B')) { + $decoder_state = 0; + return 'dn-arrow' + } elsif ($code == ord('C')) { + $decoder_state = 0; + return 'right-arrow' + } elsif ($code == ord('D')) { + $decoder_state = 0; + return 'left-arrow' + } + + $decoder_state = 0; + return undef; + + } else { + + if ($code < 27) { + + if ($code == 9) { + return 'tab'; + } + + return 'ctrl-' . chr($code + ord('a') -1); + } + + if ($code > 32 && $code < 127) { + return chr($code); + } + + if ($code == 32) { + return 'space'; + } + + if ($code == 127) { + return 'backspace'; + } + + if ($code == 27) { + $decoder_state = 1; + return undef; + } + + return 'unknown ' . $code; + } +} |