ЭЛЕКТРОННАЯ БИБЛИОТЕКА КОАПП |
Сборники Художественной, Технической, Справочной, Английской, Нормативной, Исторической, и др. литературы. |
15.6. Reading from the KeyboardProblemYou want to read a single character from the keyboard. For instance, you've displayed a menu of one-character options, and you don't want to require the user to press Enter to make their selection. SolutionUse the CPAN module Term::ReadKey to put the terminal into use Term::ReadKey; ReadMode 'cbreak'; $key = ReadKey(0); ReadMode 'normal'; DiscussionTerm::ReadKey can put the terminal into many modes - Example 15.1: sascii#!/usr/bin/perl -w # sascii - Show ASCII values for keypresses use Term::ReadKey; ReadMode('cbreak'); print "Press keys to see their ASCII values. Use Ctrl-C to quit.\n"; while (1) { $char = ReadKey(0); last unless defined $char; printf(" Decimal: %d\tHex: %x\n", ord($char), ord($char)); } ReadMode('normal'); Using An argument of Recent versions of Term::ReadKey also include limited support for non-Unix systems. See AlsoThe |