Re: Getting the current state of the modifier keys
Re: Getting the current state of the modifier keys
- Subject: Re: Getting the current state of the modifier keys
- From: Jeffrey Mattox <email@hidden>
- Date: Sat, 22 Feb 2003 18:33:58 -0600
Thanks, Greg, that worked fine. Now I'm stumped by another thing.
Before executing the code you suggested (to wait for the modifier
keys to be released), I need to get the current state of the modifier
keys. This returns the correct results when I'm the active
application:
UInt32 flags = GetCurrentEventKeyModifiers();
But, if I'm not the active application, then the flags returned are wrong.
My handler is getting triggered by a click on the status bar and some
other application is usually frontmost at the time. My application
stays in the background, and my menu item handler does not have
information about the current event, so GetCurrentEvent() returns
null and that must be why GetCurrentEventKeyModifiers() fails, too.
Is there a reliable way to get the current state of the modifier
keys, even when I'm not active?
Jeff
At 2:03 PM -0800 2/22/03, Greg Titus wrote:
On Saturday, February 22, 2003, at 01:07 PM, Jeffrey Mattox wrote:
I have a Cocoa routine that gets a single keystroke or mouse click
event. If a modifier key is down, I want to wait until the
modifier key is released before proceeding. My routine only gets
the one event, not any others. Is there a way to test the current
state of the modifiers without getting another event?
No. But you can just keep getting flag changed events until the
modifier changes.
I know how to test the event to see if a modifier key was on, but I
need to wait for the key(s) to be released.
You need to run your own little modal event loop, and wait until you
get a flags changed event with the modifier released:
NSEvent *event;
do {
theEvent = [NSApp
nextEventMatchingMask:NSFlagsChangedMask untilDate:[NSDate
distantFuture] inMode:NSEventTrackingRunLoopMode dequeue:YES];
} while ([theEvent modifierFlags] & NSAlternateKeyMask);
Hope this helps,
- Greg
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.