• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag
 

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Sending keyboard events with unicode strings causes Pages/Keynote/Numbers to hang
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Sending keyboard events with unicode strings causes Pages/Keynote/Numbers to hang


  • Subject: Re: Sending keyboard events with unicode strings causes Pages/Keynote/Numbers to hang
  • From: Huy Phan <email@hidden>
  • Date: Fri, 17 Aug 2012 11:25:17 +0800

Hi Ken,

Above you mention 2-byte unicode characters and here you mention 1-byte unicode characters.  What precisely do you mean?  A "UniChar" is inherently 2-bytes.  So the first mention (2-byte) seems redundant and the second is just wrong.
Sorry for being unclear in my question, I indeed should not explain it
that way. When I said "unicodeString contains only 1-byte unicode
character" it means Unichar from range 0x0000 to 0x00FF.
  Is there any chance you're putting an incomplete Unicode character, an unpaired surrogate, in your event?
I can confirm this is not the case as I had tried to hard code some valid Unichars (e.g. 0x20AC for € character) to test. It works fine on other applications, but not with iWork.
--
--huy


Ken Thomases <mailto:email@hidden>
13 August, 2012 10:38 PM
On Aug 11, 2012, at 3:39 PM, Huy Phan wrote:

Every time I send keyboard events with unicode strings contain 2-byte unicode characters, …
    CGEventKeyboardSetUnicodeString(keyEventDown, 1, unicodeString);
    CGEventKeyboardSetUnicodeString(keyEventUp, 1, unicodeString);
Pages doesn't hang if unicodeString contains only 1-byte unicode character.
Above you mention 2-byte unicode characters and here you mention 1-byte unicode characters.  What precisely do you mean?  A "UniChar" is inherently 2-bytes.  So the first mention (2-byte) seems redundant and the second is just wrong.

Also, note that there are some Unicode characters which can't be represented by a single UniChar.  Apple's UniChar and unichar types, the basis of CFString and NSString, are actually UTF-16 "code units", not really Unicode characters or "code points".  These terms have precise definitions in the Unicode standard, with which Apple's terminology does not conform.  Anyway, some Unicode characters will require two UTF-16 code units (a.k.a. UniChar values) to represent completely.  These are surrogate pairs.  Is there any chance you're putting an incomplete Unicode character, an unpaired surrogate, in your event?

Regards,
Ken

Huy Phan <mailto:email@hidden>
12 August, 2012 4:39 AM
Hi all,

I'm having this weird issue after upgrading iWork on Mountain Lion.
I wrote a small app to monitor and modify user's keystrokes, it works fine with other applications except latest version of Pages. Every time I send keyboard events with unicode strings contain 2-byte unicode characters, Pages will hang.
My code to simulate keystrokes is just simple like this:

CGEventRef KeyHandler(CGEventTapProxy proxy, CGEventType type, CGEventRef event, void *refcon)
{

    ......

    CGEventRef keyEventDown = CGEventCreateKeyboardEvent( NULL, 1, true);
    CGEventRef keyEventUp = CGEventCreateKeyboardEvent(NULL, 1, false);

    CGEventKeyboardSetUnicodeString(keyEventDown, 1, unicodeString);
    CGEventKeyboardSetUnicodeString(keyEventUp, 1, unicodeString);

    CGEventTapPostEvent(proxy, keyEventDown);
    CGEventTapPostEvent(proxy, keyEventUp);

    CFRelease(keyEventDown);
    CFRelease(keyEventUp);

    ......

}

Pages doesn't hang if unicodeString contains only 1-byte unicode character.
I used gdb to debug Pages and noticed 2 infinite loops at that time,
not sure if it's related to this issue.
0x91f7528c in -[NSApplication
nextEventMatchingMask:untilDate:inMode:dequeue:] () which waited for
event with mask 0xffffffff
0x91f7528c in -[NSApplication
nextEventMatchingMask:untilDate:inMode:dequeue:] () which waited for
event with mask 0x00000400

Does anybody know why this is happening ? Numbers and Keynote also have the same issue.
Thanks,
_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden


References: 
 >Sending keyboard events with unicode strings causes Pages/Keynote/Numbers to hang (From: Huy Phan <email@hidden>)
 >Re: Sending keyboard events with unicode strings causes Pages/Keynote/Numbers to hang (From: Ken Thomases <email@hidden>)

  • Prev by Date: Re: Perplexity with X3D and XML
  • Next by Date: Re: How to sandbox an included framework
  • Previous by thread: Re: Sending keyboard events with unicode strings causes Pages/Keynote/Numbers to hang
  • Next by thread: Alternative method for makeViewWithIdentifier
  • Index(es):
    • Date
    • Thread