PDA

View Full Version : XSendEvent not working in Qt 5.4



ngoncalves
8th June 2016, 08:58
Hello,

As part of a GUI test automation set of tools, I am building a tool to log user keyboard and mouse events in X11, and then
latter can replay these events.

I can log events without any problem, and I am using the X11 XSendEvent() function to generate fake user events.
However in Qt applications, replay of events does not working 100%:

- the keyboard modifiers (ALT, SHIFT, CTRL, etc) are ignored. On an US QWERTY keyboard, simulating a "SHIFT + 1"
should produce "!" but instead I get "1".

- the mouse button click events are sometimes ignored, but I can't really see a pattern

Googling, I found these similar reports but they were not answered:

https://bugreports.qt.io/browse/QTBUG-49448
http://www.qtcentre.org/threads/63126-XSendEvent-failed-for-unicode-special-characters-in-Linux

Can anybody provide some light on why is Qt 5.4 handling X11 XSendEvent() generated events in such a weird way ?

ChrisW67
8th June 2016, 13:30
Curious. Using xdotool:

xdotool search --class "test" key shift+1
and QTExtEdit under Qt 4.8.6 (Linux 64-bit) works reliably, under Qt 5.5.1 fails reliably.

ngoncalves
8th June 2016, 15:06
And what I find most weird is that I can generate normal key presses (that is without modifiers),
but not key presses with modifiers. This definitively feels like a bug in Qt

anda_skoa
8th June 2016, 19:41
It would also be interesting to test this with a non-Qt application that uses XCB.

One of the differences between Qt4 and Qt5 is the switch from XLib to XCB as the client side X11 protocol implementation, there could be a bug in there as well.

Cheers,
_

ChrisW67
8th June 2016, 21:47
Maybe processing "raw" events rather than cooked ones. Processing discrete shift key down, 1 key down, 1 key up, shift key up events and not a single event with modifiers.

ngoncalves
9th June 2016, 09:23
anda_skoa, thanks for the tip about the change to XCB. I was not aware of it, and I will try latter this week to use the XCB functions for generating the fake user events.

ChrisW67, already tried generating a "shift down" then a "key 1 down", and it also does not work.

ngoncalves
13th June 2016, 08:30
I was not able to completely fix the problems, but got close.

I first tried a source code example that I found in the XCB repository, for simulating user events. This simply did not work
and instead I got all kinds of weird behavior. I am not sure why, maybe the example source code needs to be updated or
I did not have the correct libraries installed.

Then I tried the XTest extension, instead of XSendEvent, for faking the mouse button and keyboard press/release events.
I am now able to simulate a user typing chars that require shift (for instance, "!" or "?" on a US QWERTY keyboard) although it
seems that the timing between consecutive key press and release events is crucial.

Long weekend story short, it kind of works with the XTest extension. I was hopping to be able to record X11 user events and then
replay directly, but it is not possible in what concerns keyboard events. The reason is that X11 gives a keycode (aka an identifier for
the key on the keyboard) which then has to be mapped to a symbol. This mapping is not straightforward and therein lies my problem
in simulating a user typing text.

anda_skoa
13th June 2016, 09:21
If the application doing the recording/replay and the application being remote controlled are both Qt, you could be recording Qt events instead.

That's what tools for blackbox/gui testing do (as they need to be able to query object properties anyway).

Cheers,
_