Linux - DesktopThis forum is for the discussion of all Linux Software used in a desktop context.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
The problem is that if I change the active window of a window during step 2, then the function will have no effect. If the window has not changed, the key will be pressed successfully.
What causes this behavior? Is it easy to get around this (including, for example, a simple change and recompilation of the xorg server)? Is there a better way to send an input keyboard/mouse event?
Code:
PHP Code:
// Send a fake keystroke event to an X window. // by Adam Pierce - http://www.doctort.org/adam/ // This is public domain software. It is free to use by anyone for any purpose.
#include <X11/Xlib.h> #include <X11/keysym.h> #include <iostream> #include <unistd.h> using namespace std; // The key code to be sent. // A full list of available codes can be found in /usr/include/X11/keysymdef.h #define KEYCODE XK_A
// Function to create a keyboard event XKeyEvent createKeyEvent(Display *display, Window &win, Window &winRoot, bool press, int keycode, int modifiers) { XKeyEvent event;
Distribution: Void, Linux From Scratch, Slackware64
Posts: 3,154
Rep:
Quote:
Originally Posted by Franek11
Is any method (maybe other function or something) to do it in the background (as user or as root)?
This is nonsensical, it doesn't matter what user you are using as long as they can communicate with the X server, the code you show is C++ and needs compiling etc, if you need to do this from the command line please make that clear and there are plenty of tools to do this just search.
I mean, I'd like to control two programs at once. One by me using the keyboard (live), the other in the background controlled by the program. Changing the window with the active focus causes the keyboard events to go to another window.
My guess is that it could be security or xorg server property. Therefore, there is no problem if I had to make some minor modifications to the settings or code. Unless it will require a large amount of work.
As I wroted all I need is to control two or more program at once. To achieve this I want to use the program like this one written above. The problem is that the function used there does not work when the focus is not connected to the window.
I would like to achieve that goal is accomplished two tasks simultaneously:
1. The ability to continuously click and write, e.g. in a web browser or other programs using the keyboard.
2. A program written, compiled and running will control other windows (one, two or more) simultaneously.
I used the xsetinputfocus function, but unfortunately it requires moments of time between the change of focus (maybe milliseconds or more depending on the load). If it is possible, I would prefer to do it in a more universal way, without tricks such as replacing the focus by pressing the key and returning the focus to the previous window.
Quote:
Originally Posted by AwesomeMachine
The whole point of window focus is that the keyboard attaches to it. Otherwise, how does the keyboard know where to be active?
XSendEvent gets a desktop and window id, but the event doesn't take effect if the window doesn't has a focus.
Have you ever tried to get someone to do something for you while they're sleeping? You have to wake them up to get their attention to focus on something.
A program written, compiled and running will control other windows (one, two or more) simultaneously.
simultaneously: that is just an ideal world, CPU takes instructions and processes them one at a time, a queue is involved in this endeavor.
threading:
Multi-Processers:
Hyper-threading:
capturing the the child's process ID
two children, who are their parents?
get PID from each child, put them in the back ground, then schedule them to do whatever whenever.
that is just theoretical programming ideas, or spit balling. but its something.
If i play games in windowed mode, It doesnt allow me to change the gamma in game; however, I can change the gamma in the catalyst control center. Have you tried that?
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.