cdlaforc has asked for the wisdom of the Perl Monks concerning the following question:
Not much code because I just started, but any help on the most efficient design would be greatly appreciated. Thanks, Chris.#!/usr/bin/perl use Term::Info; use Term::ReadKey; use Term::Size 'chars'; ($cols, $rows) = chars; ReadMode 4; # Turn off controls keys sub userInput { $key = ReadKey(-1); if (not defined($key)) { #do nothing } elsif ($key eq "\e") { $key = ReadKey(-1); if ($key eq "[") { $key = ReadKey(-1); if ($key eq "A") { print "Forward\n"; } elsif ($key eq "B") { print "Backward\n"; } elsif ($key eq "C") { print "Right\n"; } elsif ($key eq "D") { print "Left\n"; } } } elsif ($key eq "q" or $key eq "Q") { #Change to exit function exit 0 } else { print "Get key $key\n"; } updateScreen(); } sub updateScreen { #add code to refresh screen userInput(); } #Accept user input userInput(); ReadMode 0;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Most efficient design
by almut (Canon) on May 11, 2009 at 20:42 UTC | |
|
Re: Most efficient design
by John M. Dlugosz (Monsignor) on May 11, 2009 at 21:23 UTC | |
|
Re: Most efficient design
by CountZero (Bishop) on May 12, 2009 at 06:24 UTC | |
|
Re: Most efficient design
by salva (Canon) on May 11, 2009 at 21:51 UTC |