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.
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.
If you are comfortable using a program, have a look at Logkeys project
. It directly takes input from /dev/input/event*.
Related
I am interested in writing a program for linux that will read ALL keystrokes, process it and THEN output to the rest of the running processes. Essentially, ALL keyboard input must go into this program and this program alone...Then the program will act as the keyboard for the rest of the computer. I basically want to do something like predictive text on android devices, so my program will act as a filter.
What i'm asking is basically how to direct all keyboard events to my program. While i am not looking for code, i would like to know what part of linux programming/ linux system do i have to learn to be able to complete this task? this, because i am doing this in an attempt to better learn linux.
You shouldn't modify keyboard drivers since this will require you to have a solution for every keyboard manufacturer.(and there are quite a lot of these..)
Instead you should patch a kernel function that is called by all drivers before passing the input further up the stack.
To start with, you could patch input_event which is usually called by all input drivers see documentation here (not only keyboard but also mouse and other devices)
In any case you will have to "decode" the input scan code where you might find this documentation useful.
For more information on kernel patching read here and here.
I am writing an C++ Application and have to read if an arrow key is pressed or not.
I only found some function that are only working on Windows.
You have such problem because you just ask the wrong question. If you application is a command line tool and is accessible from a terminal, than it's just impossible to know which keys are pressed at the moment because the terminal can be far away from the machine where your application runs and which is more important, there is no reason for terminal to send you the arrow key presses because terminal can use them for text navigation.
So you may search how to make the terminal to send you key presses. Not every terminal will support it, but, I think, most of modern terminals in modern OS do.
If you has a gui application that is for running locally and assuming that you control it from the keyboard that is plugged in. Than you should search for the documentation for your gui toolkit. (Qt, wxWidgets, raw xorg, windows API, etc.)
So there are just no native C++ solution for this problem because you question just has no sense in many situations.
So you can use some console library like ncurses or gui toolkit like Qt or search for a native solution in your particular situation, but don't expect this last way will work without any additional code on other machines.
Or just search for other libraries that can allow you to do it.
As you say you only found material for Windows, I assume you are looking for a Linux-Unix way. Old dinosaurs like me remember the time when we only had true consoles (only a keyboard and a 80x25 display). And in these early times existed low-level libraries to interpret keypad transmitted keys and position cursor on screen on almost any terminal, and higher level ones to use the screen as a (text only) GUI.
You should look for curses or ncurses for high level libraries, and terminfo for the low-level capabilities.
I've been making a simple application which is able to launch a variety of other applications through QT5 (using QProcess class) but I've been running into a few key issues with the design. Specifically, it seems that Qprocess cannot set focus to windows that have been created via QProcess' start() function. This means that once a user opens more than one window, it can never return to the previous window that has been opened. After looking further into this dilemma, it has become clear that my program will need to be able to handle basic window management in order to fulfill my specifications.
I've decided that the best example to study for my program is Docky, which is capable of opening, closing and switching windows. Looking at the source code for that project was helpful, but there were many C# system calls that were used for fetching the list of client-windows which aren't available for my C++ program.
How can I get a list of all the X11 Windows that the client is running and provide basic window management (Switch To/ Open / Close Window) using C++? Is there a cross platform way of doing this through QT? Can I get this information directly using XServer?
Is it possible to make a program auto run (execute) when the USB it is stored on is plugged into a computer
I don't think this is possible due to the searching I have looked at on the Internet and also the security risk such coding would have
E.g. I have a simple countdown timer (10 to 1) programmed in C++ (complied on windows), when the USB (which the .exe file is stored on) is plugged into a computer the timer will start without me executing it manually.
You can create an Autorun.inf file and place it on the USB drive. Windows will read this file when the drive is connected. In the file you can specify the name of the program you'd like to run, as well as icons, etc.
You cannot force the program to run when the USB drive is inserted. That's up to the security policy of the operating system, and most will at least prompt the user "Do you want to run 'Setup.exe' from this drive?" or something like that.
By default it's not possible, since Windows puts users in control of their computers as much as possible—if they don't want autorun enabled, it will not be possible to have a program executed automatically.
You could write a helper program that runs in the background (possibly as a service) that sleeps most of the time, waiting for a USB device to be plugged in. There might be a way to receive notifications of this, or you might just have to poll it periodically, I don't know. Once it detects a USB device, it can then of course do whatever it wants (CreateProcess etc.).
Since Windows 7, the autorun.inf file is ignored when it comes to USB devices. U3 technology allows a thumb drive to be treated as a CD/DVD which might be a possible solution.
I think you can do so using system(), if you are familiar with disktype command in cmd, then I think you can figure things out. All what you can do in command prompt you can also do in c++ using system(). But it will consume alot of memory space
I want to create a C++ application that is to run on some Linux platform on a specific laptop computer. I do however not want the users of this laptop to use any other applications/system features than this program - much like the kiosk modes you would find on computers in a typical internet café.
One issue is that the laptop will be booted by the user, and such has to start my software automatically - leaving as little room as possible for the user to intervene with the process. It does not have to be completely secure, but it should be as close as possible.
What would be the best way to accomplish such a thing? Does there exist (free) Linux distributions specifically made for this (if not, I will probably use Arch Linux)? Are there any steps I could/should take in my program, or can I leave it all to the OS? Would creating my own little Linux distribution specifically for this be worth it?
This shouldn't be on stackoverflow but anyway:
Run a plain X session with no window manager, into this plain X session start your program in fullscreen. Done.
I run a small XUL application this way:
X :10 &
sleep 10
DISPLAY=:10 xulrunner ~/zkfoxtemp/application.ini
I would use a minimal live linux distribution - I prefer tinycorelinux but most will do.
using a minimal distribution ensures that the system doesn't have almost any features or programs you didn't plant there, and will make it easy to modify according to your needs
use a window manager as many programs don't behave properly if ran in plain X session (especially if they use pop up windows), but remove all it's menus and shortcuts
prefer booting from a read only media - this will minimize the chances of corruption (accidentally or intentionally)
remove unneeded services and features from the boot and login scripts