Toggle an object (image) when Command key is pressed: flagsChanged?
Toggle an object (image) when Command key is pressed: flagsChanged?
- Subject: Toggle an object (image) when Command key is pressed: flagsChanged?
- From: Patrick Robertson <email@hidden>
- Date: Tue, 26 Jul 2011 20:50:03 +0100
Hi all,
I'm wanting to toggle an object between its default and 'alternate' state
(the object is made up of an image and some text) when the user hits the
command (⌘) key. An obvious example is in Xcode 3.2 where if you press ⌥ the
'Build and Run' icon and text changes to 'Build and Debug' (or vice versa,
depending on your breakpoints)
The object is in a custom view which is a sub (sub) class of NSControl →
NSView etc. etc.
I assumed I'd be able to use
- (void)flagsChanged:(NSEvent *)theEvent {
if ([theEvent modifierFlags] &NSCommandKeyMask) {
// change the image
}
// when keys are lifted so there are no modifiers
if ([theEvent modifierFlags] & **NSNoKeys**) {
// set the image back to the original
}
}
but have come across a few problems.
First, you can see from the code that I can't seem to find a mask for when
'no' modifier keys are pressed. This method does get called for key downs
and key ups. It seems 'no keys' corresponds to 0x100, but is there no
constant I can use?
Secondly, this method seems to get called when other key combos are pressed
(e.g. ⌘S or ⌘Q). This means the object/image will flick back/forward, which
isn't entirely desirable.
Any suggestions would be greatly appreciated.
Thanks
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please 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