How to fetch data in a background process in Ubuntu
Asked Answered
E

2

0

I am finding a Ubuntu OS command, which lets the program to read the data from keyboard even if the program is in background. I tried to search it a lot but got no success. If any Ubuntu/Linux programmer knows the OS command which lets the program to do so, Please share it with me.

I am a beginner of Ubuntu programming.

Emporium answered 5/10, 2012 at 10:13 Comment(0)
S
1

You can use the Linux input subsystem to read events from mice and keyboards. It will only work if your application has the necessary privileges. Basically, you have to run the application as root for this to work.

If you cannot run as root, you should not be attempting to monitor the keyboard anyway.

You can create an X11 application to monitor keyboard events in the current session. It only works for the current user, and in the current graphical environment, and may not be able to observe privileged dialogs, for example password inputs. For details, look at the application shortcut launcher for your desktop environment; all Linux DEs I've ever heard of have one.

I think the old Linux Journal articles, The Linux USB Input Subsystem and Using the Input Subsystem, are still one of the best introductions to the Linux input subsystem. Most Linux distributions nowadays also support uinput, a similar device that allows injecting input events back to the kernel subsystem, designed to allow user-space input device drivers. Their interfaces are described in /usr/include/linux/input.h and /usr/include/linux/uinput.h. I recommend you start at the above articles, and then look at some input and uinput examples.

Storax answered 5/10, 2012 at 20:41 Comment(0)
S
0

If you are comfortable using a program, have a look at Logkeys project . It directly takes input from /dev/input/event*.

Scotch answered 16/5, 2018 at 8:56 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.