Cool tricks with AT codes

X11

It's fairly straightforward to use the Mouse state and remap the events into X11 keypresses.

 #!/usr/local/bin/perl -w
 use lib qw(lib);
 use strict;
 use Device::Ericsson::AccessoryMenu;
 use Device::SerialPort;
 use X11::GUITest qw(PressKey ReleaseKey);
 my $port = shift || '/dev/rfcomm0';
 my %keymap1 = ( ... );
 my %keymap2 = ( ... );
 sub translate_keys {
     my $remote = shift;
     my %keymap = @_;
     $remote->mouse_mode( callback => sub {
                              my ($key, $updown) = @_;
                              return unless exists $keymap{$key};
                              $updown ? PressKey($keymap{$key})
                                      : ReleaseKey($keymap{$key});
                          });
 }
 my $menu = Device::Ericsson::AccessoryMenu->new(
     port => Device::SerialPort->new( $port ) || die,
     menu => [ XKeys => [
         Map1 => sub { translate_keys( shift, %keymap1 ) },
         Map2 => sub { translate_keys( shift, %keymap2 ) },
        ],
     ],
    );

Being Perl this naturally has a real and practical application.