Keyboard support in C (was Re: making characters disappear)

Peter da Silva peter at ficc.ferranti.com
Sat Mar 2 08:46:27 AEST 1991


In article <14542 at ganymede.inmos.co.uk> conor at inmos.co.uk (Conor O'Neill) writes:
> The function ("inkey", or whatever it might be called) could simply
> return an error code if it could not be supported.

Perhaps a better model would be something like:

	open_keyboard()	/* tell the library you're gonna do something
			 * with the keyboard, return YES/FAILURE */
	set_mode(ECHO|NOECHO|LINE|CHARACTER)	/* Set echo/erase/etc mode */
	check_key()	/* return YES/NO/FAILURE */
	wait_key(t)	/* wait t seconds for a key, return YES/NO/FAILURE */
	get_key()	/* return the key struck or FAILURE */
	close_keyboard()	/* tell the library you're through */

The result of getchar(), etc, between open_keyboard() and close_keyboard()
would be undefined, as would whether pending input was flushed.

This would keep raw I/O from interfering with stdio, and allow for systems
where setting/clearing modes is expensive and/or not transparent.

What does POSIX.1 do about this stuff?
-- 
Peter da Silva.  `-_-'  peter at ferranti.com
+1 713 274 5180.  'U`  "Have you hugged your wolf today?"



More information about the Comp.lang.c mailing list