X11 and fake keyboard / mouse events - linux

I want to know as to how do you detect if a key press event or a mouse pointer event has been generated by an (automation like) application like xdotool. Basically, I am writing an application to check if there is no real mouse or keyboard activity. In my application I want to flag idle activity only if we don't have real mouse movement or real key press/release on the keyboard. Any reference regarding this would be great. I want to do this using pure xlib API. Don't want to use XCB. Any extensions such XRecord(which I am currently using to capture events) are fine.
Thanks in advance.

Yes there is a possibility.
All X11-events which are relevant for mouse movements and clicks have a member called "send_event".
It is set to "True" if the event was sent by an application. It is "False" if it was generated by the X-Server, i.e. by a user action.
If xdotool uses SendEvent for mousclick simulation than you'll be able to detect that using the "send_event" member.

Related

Window manager for linux, supporting focusless windows

On my arm embedded device with a touchscreen, I have a 3rd party program (program A), that creates a window which handle keyboard presses. Because of that, this window always has to have focus. This is a closed source, and I do not have options to modify it.
I need to create a window in linux, that never grabs focus. It just shows an image, some times full screen. However, I have options not to make it full screen (1 pixel less, so window below is visible.).
Right now, I am using only X server, but I can install (almost) any window manager.
Is there a way to create a window in X, that never gets focus? If I understand X correctly, a window bellow mouse will get focus.
Is there a window manager, which supports such feature?
Is this possible to do with with xcb or wayland?
On Wayland, it's up to the compositor to tell the client whether it has focus or not, and which surface(s) to send key events to. So it would depend on the compositor or compositor toolkit you're using if it's possible.
KWin has an option that sounds like it does what you want. Right click the window title bar and choose more actions -> special window settings -> accept focus
Of the compositor toolkits, I only know the Qt Wayland Compositor API, and with that it should be possible (assuming your application can run as a Wayland client). The easiest thing would be to just show the image in the compositor using the QML APIs, or you could set enabled: false on the WaylandQuickItem or ShellSurfaceItem that you don't want to grab input focus.

Simulate Click on Chromebook

I am trying to create a Chromebook application that can map keyboard input to a screen click. Is there an API that enables you to simulate a click on your Chromebook in a desired position?
Example: A user presses 'A' on the keyboard and then the app simulates a screen click in the position 100(x), 120(y).
Thanks.
The answer is basically no.
There is no API to simulate input in other apps (such as your example). You would also not be able to capture keyboard outside very limited "global shortcut" input while another app is focused.

How to handle mouse move and keyboard press in nw.js?

I'am using nw.js to create some app. One of my tasks is determine user activity.
Can i use some modules or something to handle mouse move and key press events?

QWidget / X11: Prevent window from beeing activated/focussed by mouse clicks

I would like to develop a system-wide onscreen keyboard in Qt/QML. Injecting key-events via xlib works fine.
My problem now: If a keyboard-button is clicked, the window with the selected input field will lose the focus. In consequence, the key event will not be delivered to the previously selected input field.
So does anybody know how to prevent a QWidget from beeing activated/focussed by mouse-clicks? Every hint is welcome and a code examples would be great!
Thank you very much in advance,
Frime

Click events in linux using opencv

I am doing a project to control mouse events by hand gestures using opencv in linux. I am able to control the mouse pointer with my hand movements.
I have achieved counting the number of fingers in the hands. I want to trigger mouse events depending upon the number of fingers shown. In windows there is a function mouse_event. But i am working in linux.
If there is any function for click events in opencv(linux) please let me know. Also help me with the header files to be included for those functions.
Thanks in advance!!
You can use Xlib library for handling mouse events in Linux environment. Xlib is an XWindow System protocol library. It contains functions for interacting with an X server. Main advantage of using Xlib in you project is that, you can handle mouse events globally( throughout the desktop, or in other window, not locally in your application window ).
Check out Xlib-MouseClick.
Just call the function mouseClick() in your program with argument -
0 - for left click,
1 - for middle click, and
2 - for right click, at current position of mouse pointer.

Resources