Re: examining keyboard state ?
Re: examining keyboard state ?
- Subject: Re: examining keyboard state ?
- From: Simon Stapleton <email@hidden>
- Date: Wed, 26 Sep 2001 10:03:42 +0100 (BST)
>
From: Dan Wood <email@hidden>
>
Subject: Re: examining keyboard state ?
>
To: email@hidden
>
Cc: Cocoa Development <email@hidden>
>
>
You say you're not "using" NSEvent but it sounds like you need to,
>
if you're responding to an action. Ge the current event, and then
>
get the modifier flags. For example, this determines if the option
>
key was down at the event:
>
>
NSEvent *event = [NSApp currentEvent];
>
int modifierFlags = [event modifierFlags];
>
BOOL optionDown = (0 != (modifierFlags &
NSAlternateKeyMask) );
Of course, you should always remember to use the 'bitwise' and (&)
and not the 'logical' and (&&). Failure to do this will give you an
application that _almost_ works (normal unmodified clicking will work
perfectly, but all modifier keys will be effectively the same, so you
won't be able to distinguish between, for example, NSControlKeyMask
and NSCommandKeyMask) Not that _I've_ ever been bitten by this, you
understand, but a - ahem - yes, that's it - a 'friend' of mine once
was. Repeatedly. ;-)
>
>
There may be other ways for asking "is the option key currently
>
held down", not associated with an event, but I haven't explored
>
that yet.
Override your view's 'flagsChanged' method. See NSResponder for more
details.
Normally, though, (and certainly in the context of the originally
asked question) you won't need to do much more than checking the
modifierFlags in your 'mouseDown' method.
Simon
--
PGP Key ID : 0x50D0698D
--
If the answer isn't obvious, the question is a distraction. Go find
an easier question.