Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl
- use warnings;
- use strict;
- use Term::ReadKey;
- use Data::Dump qw(dump);
- my $direction = {
- A => 'UP',
- B => 'DOWN',
- C => 'RIGHT',
- D => 'LEFT',
- };
- sub ir {
- my $key = shift;
- my $cmd = "irsend SEND_ONCE LG_42H3000 $key";
- warn "# $cmd\n";
- system($cmd);
- }
- ReadMode 4; # Turn off controls keys
- my $key;
- my $esc;
- while(1) {
- while (not defined ($key = ReadKey(-1))) {
- # No key yet
- }
- print dump($key, $esc), $/;
- if ( $key eq 'q' ) {
- ReadMode 0; # Reset tty mode before exiting
- exit 0;
- }
- if ( $key eq "\e" ) {
- $esc = $key;
- } elsif ( $esc ) {
- $esc .= $key;
- }
- if ( $esc && $esc =~ /\e\[([ABCD])/ ) {
- printf "arrow: %s %s\n", $1, $direction->{$1};
- ir('KEY_' . $direction->{$1});
- $esc = '';
- }
- ir('KEY_MENU') if $key eq 'm';
- ir('KEY_INFO') if $key eq 'i';
- ir('KEY_POWER') if $key eq 'p';
- ir('KEY_OK') if $key eq 'o' || $key eq "\n" || $key eq " ";
- ir('KEY_EXIT') if $key eq "\x7F"; # backspace
- }
Add Comment
Please, Sign In to add comment