know what key is pressed

hi

i�m making a program, and i would like to know how can i know what key was pressed. i'm using Sun5.7 and C.

is there a keypress/keypressed function in C?
how can i know recognize the keys (enter, tab, shift, etc.)?
can i recognize two keys ? (shift+A, ctrl+C, etc)

any idea.. thanks

You can do some of that. See this thread.

you are going to implement the combination of keys ie., shift+Alt then we have option in c.

First of all you have find the octal value of the combination of key pressed.

To find octal value

void main()
{
char ch;

ch=getch();

printf("%o",ch);

}

The above coding will show the octal value of the key pressed.

If suppose you want to implement it in a program, then you have to specify as follows

For instance Shift+Alt 's octal value is 146 then the implementation is,

if ch=='\146'

The above condition will true when ch is Shift+Alt.

regards

Senthil. K

this code works for me.....

Consider using int ch because getch returns an int. In the same vein, main()
returns an int - per C standard. After void main() executes, the value of the command line paramter $? can be literally anything - if it's zero then it's pure luck that it was zero. You can crash scripts by calling void main() C from them.