Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Bad simulated keyboard event received in Qt application under Mac OS
Forum Updated to NodeBB v4.3 + New Features

Bad simulated keyboard event received in Qt application under Mac OS

Scheduled Pinned Locked Moved General and Desktop
3 Posts 1 Posters 1.7k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    dMathieuD
    wrote on 24 Aug 2012, 10:15 last edited by
    #1

    Hi,

    I'm developing a Mac OS application, an input method, which purpose is to send text to other targeted application. I'm using this portion of code to do that:
    @
    CGEventRef vKeyDown = CGEventCreateKeyboardEvent(NULL, (CGKeyCode)0, true);

    // Get the unicode String to use to send
    int stringLength = [string length];
    UniChar *unicodeString = (UniChar )malloc(stringLengthsizeof(UniChar));
    NSRange range = NSMakeRange(0, stringLength);
    [string getCharacters:unicodeString range:range];

    CGEventKeyboardSetUnicodeString(vKeyDown, stringLength, unicodeString);

    GetFrontProcess(&targetPSN);

    CGEventPostToPSN(&targetPSN, vKeyDown);

    CFRelease(vKeyDown);
    @

    It's working fine appart from Qt based application. Indeed according to Azerty or Querty keyboard layout the characters received by the Qt applications are always "a" or "q". I'm wondering if this could be a bug in Qt not well supporting simulated keyboard event.

    1 Reply Last reply
    0
    • D Offline
      D Offline
      dMathieuD
      wrote on 25 Oct 2012, 13:02 last edited by
      #2

      Hi,

      I also posted a request on Apple forums and had a reply telling me that Qt is not managing the keyboard event as other native applications.

      In fact as Apple documentation said the CGEventKeyboardSetUnicodeString(…, …, unicodeString) method call can lead to different behavior once the event is posted: "Note that application frameworks may ignore the Unicode string in a keyboard event and do their own translation based on the virtual Keycode and perceived event state.". So I assume this is what happens with Qt and I went to use InputMethodKit framework as a "filter" between my application sending the keyboard event and the target application receiving it. Indeed having my own Input Method installed let me managed the keyboard event as requested propagating it to a Qt application. In order to manage input method Text Input Source Services can be use so it is transparent for the user.

      1 Reply Last reply
      0
      • D Offline
        D Offline
        dMathieuD
        wrote on 8 Nov 2012, 16:34 last edited by
        #3

        Indeed, it does not do the trick completely... After deep testing we found that when targeting Qt application built against Qt framework under 4.7 it does not work.

        Does anyone know why CGEventKeyboardSetUnicodeStringis not taken into account by Qt event monitoring loop ?

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved