开发者

Intercepting input from the OS

I would like to learn with an example before next semester and want to try something which works together with the OS.

How can a C program intercept input from the OS. The only example I can think of is a Keylogger.

How can a 开发者_JS百科C program be programmed to dig into the Operation System?

Does this make sense?


On Linux you could watch the device nodes for all keyboards and record the received events.

The /dev/input/event* nodes provide a generic interface - you would have to watch any of them that correspond to a mouse or keyboard. You need the evdev kernel module for this to be available.

The /usr/include/linux/input.h header file contains most of what you'd need to know about the programming interface. From my experience, it's quite straightforward and simple to use.

Keep in mind that some X-server drivers will grab their device node and block all other applications from getting events, so you may have to either change their options or use an X-based interface as well.

I think that this is about as far as you can get on Linux without writing a kernel module.

EDIT:

You should realise that each OS has its own interface for the input subsystem. There is no cross-platform way to do this. What exactly do you want to do?


Basically depending on OS you need to "hook" into the event mechanism of the OS. There are different events happening in an OS and a key press is an event just like a mouse click. It is possible to hook into these events and provide a function that the OS calls whenever the event happens.

E.g. see for Windows

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜