How to get Key codes

Hi Experts,
I like to get the Key codes of the keys in the Keyboard while I press it.
Its something like scan code.
I want to know which key had been pressed.

Can anyone fine me a solution for this using C.

Regards
Anent

Look for a program named 'xev' or one named 'showkey' as examples.

PxT,
where can I find these examples.
i searched around various directories in my harddisk. but no result.

Anent

Hi!

If you are planning to implement the code in a C program, you can use the CURSES.H library, or the TERMIO.H library

Rgds
SHAIK

Xev: http://ftp.xfree86.org/pub/X.Org/pub/unsupported/programs/xev/

Thanks for u all,
Can anyone get me a C code for the above operation.

Thanks in Advance.
Anent

#include < stdio.h >
#include < curses.h >

main()
{
int ch;

initscr();
ch = getch();
endwin();

printf(" %d\n", ch);
}

If you are not familier with CURSES.H library, refer the man pages on the same to learn more of it. The above is the simplest of programs presented.

Rgds
SHAIK

Hi Shaik,
I tried the code which got me some messages that i could not understand.
could you please look into that.

I ran it on HPUX B.11.00
The message is as follows..

/usr/ccs/bin/ld: Unsatisfied symbols:
stdscr (data)
wgetch (code)
initscr (code)
endwin (code)

Those routines are in the curses library. When you compile you need to do something like:
cc whatever.c -lcurses -o whatever

thanks Perderabo,
it is working fine
:slight_smile:

Hi Shaik, Perderabo,
I got it, its working fine.
Many Thanks to All

Wish You all a Very Happy New Year 2002!!!:wink:
Anent

Hi All.
I am still a beginner in Unix.I have got one program.i am not getting the solution for one program.Will anybody help me soon.

Q.write a C program which accepts a valid directory name as a command line argument and list all the files in the given diirectory as well as all the files in subsequent directories.(The solution can be recursive or non-recursive).

  I need the solution immediately.I need it desperately within 15th Jan.

See the man pages on:


opendir()
readdir()
closedir()