Results 1 to 8 of 8

Thread: XSendEvent not working in Qt 5.4

  1. #1
    Join Date
    Jun 2016
    Posts
    4
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default XSendEvent not working in Qt 5.4

    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/6312...cters-in-Linux

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

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: XSendEvent not working in Qt 5.4

    Curious. Using xdotool:
    Qt Code:
    1. xdotool search --class "test" key shift+1
    To copy to clipboard, switch view to plain text mode 
    and QTExtEdit under Qt 4.8.6 (Linux 64-bit) works reliably, under Qt 5.5.1 fails reliably.

  3. #3
    Join Date
    Jun 2016
    Posts
    4
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: XSendEvent not working in Qt 5.4

    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

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: XSendEvent not working in Qt 5.4

    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,
    _

  5. #5
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: XSendEvent not working in Qt 5.4

    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.

  6. #6
    Join Date
    Jun 2016
    Posts
    4
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: XSendEvent not working in Qt 5.4

    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.

  7. #7
    Join Date
    Jun 2016
    Posts
    4
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: XSendEvent not working in Qt 5.4

    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.

  8. #8
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: XSendEvent not working in Qt 5.4

    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,
    _

Similar Threads

  1. XSendEvent failed for unicode/special characters in Linux
    By Deepika in forum General Programming
    Replies: 0
    Last Post: 16th July 2015, 06:05
  2. Replies: 0
    Last Post: 16th July 2015, 06:05
  3. Replies: 7
    Last Post: 24th September 2012, 07:17
  4. Working with map
    By naptizaN in forum Newbie
    Replies: 4
    Last Post: 28th August 2012, 12:57
  5. MVC example not working
    By yyiu002 in forum Newbie
    Replies: 1
    Last Post: 30th June 2010, 00:07

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.