0

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

Community
  • 1
  • 1
user1698102
  • 127
  • 2
  • 4
  • 9
  • 7
    Yes, I'd be delighted to help you develop spyware. Seriously, if you post an ethical reason why you want to do OS level keylogging on a Linux machine, perhaps people will help. – Jeff Watkins Oct 05 '12 at 13:05
  • This program is for educational purposes because I am learning unix/ubuntu programming – user1698102 Oct 05 '12 at 13:08
  • 4
    As a beginner, you might want to start with something that is both *simple* and *unsuspicious*. – Erich Kitzmueller Oct 05 '12 at 13:11
  • 2
    Same user, same question: http://stackoverflow.com/questions/12744064/how-to-fetch-data-in-a-background-process-in-ubuntu – Derek Oct 05 '12 at 13:37
  • @user1698102: you should hear less (hearing about an OS specific system call to monitor keyboard is bullshit) and read, study, experiment and code much more. – Basile Starynkevitch Oct 05 '12 at 14:33

3 Answers3

2

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.

Basile Starynkevitch
  • 223,805
  • 18
  • 296
  • 547
0

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.

cdarke
  • 42,728
  • 8
  • 80
  • 84
0

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.

Pavel Ognev
  • 962
  • 7
  • 15
  • It is an X11 client, and we don't know if the OP talks about key presses as seen by Xorg, or as seen by X11 clients, or as seen by console application, or as seen by the kernel. – Basile Starynkevitch Oct 05 '12 at 17:13