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. CGEventKeyboardSetUnicodeString will only process up to 20 characters

CGEventKeyboardSetUnicodeString will only process up to 20 characters

Scheduled Pinned Locked Moved General and Desktop
1 Posts 1 Posters 900 Views
  • 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.
  • M Offline
    M Offline
    mark_in_gr
    wrote on last edited by
    #1

    I have a Qt app which simulates key strokes and when I sent a QString to the following function, it will only send up to 20 characters to output. At first I thought this may have something to do with UTF8/UTF16 encodings, but I am not sure at this point. My code is:

    @NSString * text = [NSString stringWithUTF8String: pTextToPrint.toUtf8().data()];

    //const char *buffer = [text cStringUsingEncoding:NSUTF16StringEncoding];
    
    CGEventSourceRef eventSource = CGEventSourceCreate(kCGEventSourceStateHIDSystemState);
    CGEventRef keyEventDown = CGEventCreateKeyboardEvent(eventSource, 0, true);
    CGEventRef keyEventUp = CGEventCreateKeyboardEvent(eventSource, 0, false);
    
    int stringLength = [text length];
    qDebug() << "stringLength is " << stringLength;
    UniChar *unicodeString = (UniChar *)malloc(stringLength*sizeof(UniChar));
    NSRange range = NSMakeRange(0, stringLength);
    [text getCharacters:unicodeString range:range];
    
    //CGEventKeyboardSetUnicodeString(keyEventDown, [text length], (UniChar *)buffer);
    CGEventKeyboardSetUnicodeString(keyEventUp, stringLength, unicodeString);
    CGEventKeyboardSetUnicodeString(keyEventDown, stringLength, unicodeString);
    CGEventPost(kCGHIDEventTap, keyEventDown);
    CGEventPost(kCGHIDEventTap, keyEventUp);
    
    CFRelease(keyEventDown);
    CFRelease(keyEventUp);
    CFRelease(eventSource);@
    

    Regardless of the length of pTextToPrint, ONLY 20 characters are always sent. I have tried with a variety of values and lengths. The interesting fact is that the qDebug statement DOES reflect the correct string length.

    Has anyone ever run into this before, and if so, is there a fix? Thanks in advance.

    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