100% Spam Free Email | Contact Us | Products/Services | Korn Shell | MicroEMACS


AIXtm mtXIA Technical Consulting Group

 


getch

Korn Shell getch: Capture a single key press without requiring carriage return or enter key

See visualSelect menu system for a full implementation of "getch" capturing function keys, arrow keys, and other cursor movement keys.


Path : Home : Tools : Scripts : Korn : Functions


Current:getch
Previous:.
Home Page

shcurses
frenchMenus



################################################################
####    Korn Shell function to read one character from
####    standard input (STDIN) without requiring a carriage
####    return.  This function would typically be used in a
####    shell script to detect a key press.
####
####    Load this file into your current environment as follows:
####
####    . ./getch
####
####    Thats "dot-space-dot-slash-getch-dot-sh"
####
####    You will then be able to issue the command "getch"
####    from your current environment to retrieve one character.
####
####    SYNTAX: getch [-q]
####
####                   -q = quiet mode, no output
####
####    AUTHOR: Dana French (dfrench@mtxia.com)
####
####    See http://www.mtxia.com/js/Downloads/Scripts/Korn/Functions/visualSelect/index.shtml
####    visualSelect menu system for a full implementation of "getch" 
####    capturing function keys, arrow keys, and other cursor movement keys.
#### 
################################################################
function getch {
    typeset TMP_GETCH
    typeset STAT_GETCH="0"
    stty raw
    TMP_GETCH=`dd bs=1 count=1 2> /dev/null`
    STAT_GETCH="${?}"
    stty -raw

    if [[ "_${1}" != "_-q" ]]
    then
        print -r -- "${TMP_GETCH}"
    fi
    return ${STAT_GETCH}
}

 

For information regarding this page, contact Dana French ( dfrench@mtxia.com )
Copyright 2008 by Mt Xia Inc, All Rights Reserved