X11 and fake keyboard / mouse events
Asked Answered
T

1

6

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.

I don't want to use XCB.

Any extensions such XRecord(which I am currently using to capture events) are fine.

Tanishatanitansy answered 28/6, 2013 at 11:14 Comment(3)
Why do you want to check if there is no real mouse or keyboard activity? I suspect that some peculiar user interface (maybe for visual impaired users) might provide "virtual" mouse, etc... Why do you want to detect automation tools? (a sufficiently motivated person could always circumvent your detection, e.g. by patching adequately the Xorg server...)Shocking
@Basile, The point that you make is correct. Basically I am writing a small application which should report to me the idle activity of a user on a machine(PC). Using this data I want to determine as to how many hours in a week a person effectively does work(That is still assuming that if a person is either using mouse or keyboard implies work). Real keyboard / mouse events indicate physical activity which support the point made above. I have not thought about Accessibility provisions for this application, which I leave for later. ThanksTanishatanitansy
Are you sure that deploying such a "spying" program is legal (without explicit consent of the user)? In some country (probably in France) it probably won't be, and I am sure that any user would be able to circumvent it. People can (and do) work without always typing... and people can type without really working...Shocking
B
3

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, and 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.

Bund answered 1/7, 2013 at 6:46 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.