Nonblocking, nondestructible test for waiting data on TTYs, sockets and probably pipes
# $Header: /CVSROOT/keypressed/DESCRIPTION,v 1.1 2008-05-30 16:59:00 tino Exp $
#
# $Log: DESCRIPTION,v $
# Revision 1.1 2008-05-30 16:59:00 tino
# First try
#
- Returns 0 (true) if there is input data waiting.
- Returns 1 if no input data waiting.
- Returns 255 on errors.
- Return is undefined on unknown input types.
- Does not read or print anything.
- Does not set tty into CBREAK mode! As the tty usually is in line mode you need to press Enter for keypressed to detect the input
Example 1:
while ! keypressed; do ...; done
Example 2:
while ! keypressed
Limitations and bugs:
- The input data is not touched and stays there to be read
- Commandline is ignored for now
- Only fd0 (stdin) is checked, be sure to use poper IO redirection
-
- No Hangup detection
- Works only on input types which support certain ioctl() and select(), known to work on TTYs and Sockets and maybe Pipes.
- Behavior on unsupported types (files, non-tty devices, often Pipes) therefor is undefined. It depends on your OS if select() signals read (gives true) or not (gives false) or error (gives 2).
This Works is placed under the terms of the Copyright Less License,
see file COPYRIGHT.CLL. USE AT OWN RISK, ABSOLUTELY NO WARRANTY.
Actually this only is a minimum wrapper around a library call.