How to capture keyboard input without screen recording

I am writing ANSI C application for Debian Linux which grabs data from USB keyboard and sends some data through RS232 and LAN port (it is kind of industrial machine). No screen connected to PC. I use capture from "/ dev / input / event1" and everything works fine, but after startup the computer outputs the system login / password and the keyboard is captured by my application as well as the system login. My question is how to disable the system's keyboard capture for login, but keep it in my application?

+3


source to share


1 answer


The problem you are having is that by default all input event handlers for a device receive all events. For your case, there are at least two handlers: the keyboard driver for the console and the user interface evdev

for your application.

To avoid this, your application must instruct the module evdev

to capture the input device for its own exclusive use with EVIOCGRAB

ioctl

. This will prevent any other handler, including other user-space applications, from receiving any events from that device.

To hijack a device:



int ret = ioctl(fd, EVIOCGRAB, (void *)1);

      

To free a hijacked device:

int ret = ioctl(fd, EVIOCGRAB, (void *)0);

      

+3


source







All Articles