Re: How to create an NSEvent for Option-E?
Re: How to create an NSEvent for Option-E?
- Subject: Re: How to create an NSEvent for Option-E?
- From: Aki Inoue <email@hidden>
- Date: Wed, 30 Aug 2006 14:09:12 -0700
This isn't intended to be shipping code, just a test of a general
approach. On a US keyboard, Option-E is the beginning of a multi-
keystroke char, like "é". If you override keyDown: in an NSView
subclass and type Option-E on a US keyboard, the event that you
receive has these exact parameters, including the empty string for
the characters: parameter. At this point I'm trying to understand
how the system could generate and send this NSEvent, but I can't.
The Cocoa's design principle in this area is to avoid the event model
as much as possible and to offer higher-level abstractions.
When you need to post key events, you can directly create an NSEvent
with the final Unicode string instead of relying on individual raw
key event. Note as Uli mentioned, the result of posting the low-
level raw key event is at most unpredictable because different
keyboard layouts produce different character mappings.
Aki
On 2006/08/30, at 10:51, Glen Simmons wrote:
On Aug 30, 2006, at 12:40 PM, Uli Kusterer wrote:
Am 29.08.2006 um 23:03 schrieb Glen Simmons:
NSEvent* fakeEvent = [NSEvent keyEventWithType:NSKeyDown
location:NSZeroPoint
modifierFlags:0x80120
timestamp:0
windowNumber:[[NSApp
mainWindow] windowNumber]
context:nil
characters:@""
charactersIgnoringModifiers:@"e"
isARepeat:NO
keyCode:14];
[NSApp postEvent:fakeEvent atStart:NO];
This throws an exception: *** -[NSCFString characterAtIndex:]:
Range or index out of bounds
Why? What's wrong with this code? How can I send an event for
Option-E?
I guess AppKit isn't prepared to get an empty string for the
characters: parameter? Why do you need to do this anyway? What is
Option-E? On my keyboard, that's the Euro-sign, so you'd neither
want to use this as a keyboard shortcut, not would you want to use
a fake event to generate the character (Because it may be
different depending on the keyboard, and NSEvent won't auto-fill
the characters: param, which can cause application code to detect
this as the wrong key...).
What are you trying to do?
This isn't intended to be shipping code, just a test of a general
approach. On a US keyboard, Option-E is the beginning of a multi-
keystroke char, like "é". If you override keyDown: in an NSView
subclass and type Option-E on a US keyboard, the event that you
receive has these exact parameters, including the empty string for
the characters: parameter. At this point I'm trying to understand
how the system could generate and send this NSEvent, but I can't.
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden