Search code examples
iosobjective-cmacoscocoansevent

Under what conditions can [NSEvent characters] be a NSString of length greater than 1?


NSEvent has a characters property which is a NSString valid for key up/down events. Under what conditions can the string length be greater than 1?

The only condition I have been able to find till now is when the NSEvent corresponds to input from an IME (Input Method Editor).

Edit - I knew about the surrogate pair case, but it somehow slipped out of my mind while asking this. I am more interested in the case when the no. of graphemes(characters) is greater than 1 itself.


Solution

  • You can also get this with programmatically-posted events. CGEventKeyboardSetUnicodeString() allows the caller to attach any arbitrary string to the key event.