Guest User

Untitled

a guest
Nov 20th, 2017
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. #!/usr/bin/perl
  2. use warnings;
  3. use strict;
  4.  
  5. use Term::ReadKey;
  6. use Data::Dump qw(dump);
  7.  
  8. my $direction = {
  9. A => 'UP',
  10. B => 'DOWN',
  11. C => 'RIGHT',
  12. D => 'LEFT',
  13. };
  14.  
  15. sub ir {
  16. my $key = shift;
  17. my $cmd = "irsend SEND_ONCE LG_42H3000 $key";
  18. warn "# $cmd\n";
  19. system($cmd);
  20. }
  21.  
  22. ReadMode 4; # Turn off controls keys
  23. my $key;
  24. my $esc;
  25. while(1) {
  26. while (not defined ($key = ReadKey(-1))) {
  27. # No key yet
  28. }
  29. print dump($key, $esc), $/;
  30. if ( $key eq 'q' ) {
  31. ReadMode 0; # Reset tty mode before exiting
  32. exit 0;
  33. }
  34. if ( $key eq "\e" ) {
  35. $esc = $key;
  36. } elsif ( $esc ) {
  37. $esc .= $key;
  38. }
  39.  
  40. if ( $esc && $esc =~ /\e\[([ABCD])/ ) {
  41. printf "arrow: %s %s\n", $1, $direction->{$1};
  42. ir('KEY_' . $direction->{$1});
  43. $esc = '';
  44. }
  45.  
  46. ir('KEY_MENU') if $key eq 'm';
  47. ir('KEY_INFO') if $key eq 'i';
  48. ir('KEY_POWER') if $key eq 'p';
  49. ir('KEY_OK') if $key eq 'o' || $key eq "\n" || $key eq " ";
  50.  
  51. ir('KEY_EXIT') if $key eq "\x7F"; # backspace
  52.  
  53. }
Add Comment
Please, Sign In to add comment