Term::GetKey - A perl module for quick easy simple key control
perl Version 5.6.0 or higher is required because it uses the module warnings:
Term::ReadKey is used to change the terminal settings.
This module changes the settings of Term::ReadKey using the `\' as a toggle key. qtty() makes a single character request to Term::ReadKey which is esential for the functionality of this module. `|' toggles the case of the output character to UPPERCase lowercase or off. qtty() and keypasswd() and query() use chomp on all input.
my $ch;#$ch can be any scalar variable
$ch = qtty();#single character good for menus. The methods in this module are dynamically loded so you do not need the full prefix Term::GetKey-> prefix to call a method.
will announce the key strokes the module uses.
The Term::ReadKey reserve words:
ReadKey ReadMode ReadLine GetTerminalSize SetTerminalSize
GetSpeed GetControlChars SetControlChars
are still available and functional.
qtty() keypasswd() query() status() setkeymode()
keymode() setannounce() announcestatus() setcase() casestatus() Kmstatus() is the list of methods that do not require the full system path and module name before the method name.
When you press `|' or `\' and then a `\\n' depending on the settings you cycle through the settings of Term::ReadKey. The keys effected by Term::GetKey->qtty are disabled in noecho mode. When Term::GetKey is in (cbreak, raw or ultra-raw) modes the `\n' or enter key is not required.
setkeymode() `\\' the backslash key Terminat your program with '`' the grav accent key. warnings is used so the line number is announced so you know that Term::Getkey terminated your module fore you.
keypasswd() calls qtty to create a password. This saves a call to stty - echo and stty echo.
$opt_passwd = keypasswd();
query() calls setcase() `|'
If you wish to have a `|' as the only character on the line: `\|' will cause query() to remove the `\\' and `|' will be sent as the string.
The announcements are not disabled when you call qtty() or query() if they are waiting for a request and you press '|' or '\\'. You can disable the announcements with a call to set_announce(). The functions setcase() setkeymode() casestatus() and Kmstatus return the current value or the changed value of their called method.
0 Restore original settings. 1 Change to normal mode. 2 Change to cooked mode with echo off. (Good for passwords) strings are uneffected 3 Change to cbreak mode. 4 Change to raw mode. 5 Change to ultra-raw mode. (LF to CR/LF translation turned off)
restore normal noecho cbreak raw ultra-raw
The Default for qtty() is cbreak.
qtty() handles each key individually. It returns to the `normal' mode after each key has been pressed so that you can continue with your programming allowing you flexability. When case conversion is activated with the `|' or called via a program it takes priority over your current case settings. It saves your current setting and sets itself so that other programs run normally. The default setting for its case conversion is off (no translation). You can toggle or query the settings with the following calls:
my $myval; $myval = casestatus();
$myval = Kmstatus();
#change the case of the key requested and announce the setting
my $keymodeval; setcase();
$readval = setcase();
query();#handles lines of text.
my$opt_passwd = keypasswd();
my $textline = query();
The characters returned are set to the case setting that you set with `|'.
announcestatus announces the status of the verbosity.
The status of Term::GetKey is available by pressing `=' the equals key.
setannounce toggles the setting verbosity. The calls to the keystrokes mentioned above are only present with a call to qtty() All the Term::GetKey commands except '\\' are disabled when Term::GetKey is in noecho mode.
In noecaho mode, qtty() only has `\\' active. query() has case conversion disabled.
setcase() casestatus() Kmstatus() setkeymode() return values only when announce mode is disabled with the default.
Off 0 UPPERCASE and announcements active 1 lowercase 2
Characters can be converted by Term::GetKey no matter what the capslock or case of the character sent by the terminal.
To install Term::GetKey, copy and paste the appropriate command in to your terminal.
perl -MCPAN -e shell
For more information on module installation, please visit the detailed CPAN module installation guide.