aboutsummaryrefslogtreecommitdiffstats
path: root/feature-tests/key_test.pl
diff options
context:
space:
mode:
authorTom Feist <shabble@cowu.be>2010-07-24 17:23:13 +0000
committerTom Feist <shabble@cowu.be>2010-07-24 17:23:13 +0000
commit91f126ae4c9ea90336bdeb24001fadca79439edc (patch)
treed21b72a82b67b0979aadfa3f6efbbc2586d962b1 /feature-tests/key_test.pl
parentupdated script info to add my url and to change contact details to me (diff)
downloadirssi-scripts-91f126ae4c9ea90336bdeb24001fadca79439edc.tar.gz
irssi-scripts-91f126ae4c9ea90336bdeb24001fadca79439edc.zip
moved most tests to feature-tests/
Diffstat (limited to 'feature-tests/key_test.pl')
-rw-r--r--feature-tests/key_test.pl100
1 files changed, 100 insertions, 0 deletions
diff --git a/feature-tests/key_test.pl b/feature-tests/key_test.pl
new file mode 100644
index 0000000..b16ff00
--- /dev/null
+++ b/feature-tests/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;
+ }
+}