Fake escape key event
Fake escape key event
- Subject: Fake escape key event
- From: David Catmull <email@hidden>
- Date: Mon, 18 Dec 2006 10:46:16 -0800
I'm working on creating keyboard events for use in unit tests, and my
first test case isn't working: a cross-platform test to verify that
the escape key closes a floating palette. This is built-in behavior
on Cocoa, but I still want the test to run and pass.
The code comes down to this:
NSEvent *event = [NSEvent
keyEventWithType:NSKeyDown
location:[NSEvent mouseLocation]
modifierFlags:0
timestamp: ::GetCurrentEventTime()
windowNumber:[keyWindow windowNumber]
context:nil
characters:[NSString stringWithFormat:@"%c",&inChar]
charactersIgnoringModifiers:[NSString stringWithFormat:@"%c",&lower]
isARepeat:NO
keyCode:inVirtualKey];
[NSApp sendEvent:event];
..where 'inChar' and 'lower' are 27 (escape), and inVirtualKey is 53.
I've tried sending the event directly to the window, but that didn't
work either. No errors, exceptions, or console messages; nothing
happens.
I thought maybe the event was getting deferred somehow so that the
test was checking too soon to see if the window had closed. But if I
set a breakpoint in my windowDidResignKey: and hit the escape key
manually, I see the window being closed in the same call chain as
[NSApp sendEvent:] - as called by Carbon, since I'm dealing with
Cocoa windows in a Carbon app.
Am I making the event wrong, or sending it wrong?
--
David Catmull
email@hidden
http://www.uncommonplace.com/
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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