Re: keyboarding in C :)



On 2006-04-20, The Other Guy <tog@xxxxxxxxx> wrote:

I want to write simple app that do some thing acoording to which key was
pressed. It would be sth like this

switch(some_thing)

case (code1) :
do_sth

case (code2) :
do_else


The only problem is i know how to do it in windows (which structure holds
messages from keyboard) and i do not know how to do this in FreeBSD/UNIX.
I would be very happy if someone throw me a link to page that covers this
problem.

Are you simply wanting to do this from a command line tool, or are you
trying to handle keyboard input using one of the GUI toolkits etc?

For a command-line based application, you can just do this...

switch(getchar()) {
case 'a':
// Something
break;
case 'b':
// Something
break;
default:
// Something
break;
}

This is almost identical to what you'd do in Windows, except getchar()
would probably be replaced with getch(), depending on the compiler.

He may want to put the tty into raw mode in order to disable
line-buffering.

--
Grant Edwards grante Yow! This is PLEASANT!
at
visi.com
.