Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Fake escape key event



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:
http://lists.apple.com/mailman/options/cocoa-dev/email@hidden

This email sent to email@hidden


Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.