This question already has answers here:
Closed 7 years ago.
Possible Duplicate:
How to fetch data in a background process in Ubuntu
I am writting a program which monitors the keys pressed on a keyboard. But my program may be running in foreground or in background. I heard that there is OS specific system call which lets the programmer to monitor keyboard activity even when the program running the system call is in background. I am new to Ubuntu programming so please somebody tell me what is that OS system call.
Note:
This program is strictly for educational purposes. It is a part of School project..
Regards
Most Ubuntu systems (at least desktop for novice Ubuntu users) are running an X11 window server (like Xorg). That server (only) is getting the raw keyboard and mouse device inputs. It processes them to deliver X11 protocol events to client applications (like e.g. your firefox browser, or your emacs
editor, or your gnome or xterm
terminal).
You could spend your time (months) understanding all of them (perhaps starting from freedesktop) You could also switch to some other project, perhaps just coding an interesting GUI application using Gtk (within Gnome) or Qt (within KDE). All Linux graphical toolkits libraries are built above a library interfacing the X11 protocol, usually Xlib, or XCB.
If you want to start learning Linux programming, read Advanced Unix Programming and Advanced Linux Programming. After than, take a lot of time to understand the mysteries of tty-s, and become familiar with syscalls(2). Then become familiar with a graphical toolkit like Qt or GTK.
And then you'll just begin to understand how hard it is to answer precisely your ill-asked and suspicious question. (the answer strongly depends upon the point of view - Xorg
seeing different key events than other applications, notably X clients, and is very complex).
Once you've understood all the concepts in the links I gave you, you'll be able to ask more precisely your question. When you'll re-ask your question in more precise and technical terms (in particular explaining at which level you want to monitor the keyboard & mouse), showing the code that you experimented, we'll be able (and willing) to answer you.
heard that there is OS specific system call: who did you hear that from? Did you ask them?
This requires more than one call, you need to use ioctl
(might be different on Ubuntu) to push your logger into the terminal stream. It is not simple, and not really suitable for a beginning project. For an example, see the script
program.
There is a program for linux, which binds global hotkeys and perform predefined actions on key press. It is called xbindkeys
. Look in its source code for suggestion or simply use it as it is.