LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Reading values from standard keyboard (https://www.linuxquestions.org/questions/programming-9/reading-values-from-standard-keyboard-897813/)

prabhuraj 08-17-2011 06:21 AM

Reading values from standard keyboard
 
Hi all,
I have to write an application which will open the keyboard device file.Once the device is open, I have to define a WriteBuffer and whatever the key I press from the keyboard, the keys should be stored in the WriteBuffer and the same should be copied into the ReadBuffer and should be displayed on the console.To implement this I have to make use of the system calls in Linux.Can anyone help me in this regard?

Thanks in advance,
Prabhuraj

trist007 08-18-2011 12:46 AM

Use the read, write, open and close system calls. You can run man on these guys.

Nominal Animal 08-18-2011 05:35 PM

Is this homework?

There is no such thing as a "keyboard device file". Usually, the standard input is used for this purpose. If you need each individual keypress, you also need to use either ncurses (curses) or the termios interface (to disable canonical mode and turn off echoing, see man termios). Normally input is line-buffered, so your program does not receive individual keypresses, only complete lines, from a terminal.

If you are writing an X11 application with a graphical user interface, then you use the X11 interfaces, not system calls. Even then there is no keyboard device; keypresses and -releases and mouse movement (and many other things) are reported as events. Events are queried from the X11 server using XNextEvent; function see the manpage for details. The net is full of X11 example programs, too.


All times are GMT -5. The time now is 02:56 PM.