To my surprise [NSEvent charactersByApplyingModifiers:]
does not always produce
the same NSString
result as the originating NSEvent
reflects through characters/charactersIgnoringModifiers
, even if passing on the event's own modifierFlags
.
For example, when pressing the 'end' key, both characters and charactersIgnoringModifiers return 0x000000000000f72b
,
which matches the value of NSEndFunctionKey
. But calling [NSEvent charactersByApplyingModifiers:]
passing in
NSEvent.modifierFlags
produces 0x0000000000000004
, which matches the value of kEndCharCode
.
(lldb) po [[((NSApplication*)NSApp).currentEvent characters] characterAtIndex:0]
0x000000000000f72b
(lldb) po [[((NSApplication*)NSApp).currentEvent charactersIgnoringModifiers] characterAtIndex:0]
0x000000000000f72b
(lldb) po [[((NSApplication*)NSApp).currentEvent charactersByApplyingModifiers:[(NSEvent*)((NSApplication*)NSApp).currentEvent modifierFlags]] characterAtIndex:0]
0x0000000000000004
(The same can be observed with UCKeyTranslate
directly, which charactersByApplyingModifiers
seems to use internally).
I would expect [NSApp.currentEvent charactersByApplyingModifiers:NSApp.currentEvent.modifierFlags]
to match
either NSApp.currentEvent.characters
or NSApp.currentEvent.charactersIgnoringModifiers
.
Is there a logic behind this perceived discrepancy that I'm missing? Should I always prefer the
content of NSEvent.characters/charactersIgnoringModifiers
in this case if the modifier flags I'm applying
match those of the event itself?
Thanks for any insights!
(Also reported as FB20591338)