modifier key query
-
Is there a way to know if a modifier key (shift, ctrl, option, cmd,
etc) is pressed? Obviously, there's this:
NSUInteger modifierFlags = [theEvent modifierFlags];
but what if you need to know this information independent of an
NSEvent? Anyway to get it? So far I haven't seen anything
encouraging in the docs.
thanks,
wes -
On Dec 26, 2008, at 2:04 AM, Wesley Smith wrote:> Is there a way to know if a modifier key (shift, ctrl, option, cmd,
> etc) is pressed? Obviously, there's this:
> NSUInteger modifierFlags = [theEvent modifierFlags];
>
> but what if you need to know this information independent of an
> NSEvent? Anyway to get it?
You don't get it independently of NSEvent, you get a specific event
whenever the current set of modifiers changes, an event of type
NSFlagsChanged.
Given that you are informed with an event each time the modifiers
change, I'm not sure why you want to "know this information
independent of an NSEvent".
Regards,
Ken -
>
> Given that you are informed with an event each time the modifiers change,
> I'm not sure why you want to "know this information independent of an
> NSEvent".
Mainly because I'd like to be able to control various animating
behaviors via key modifiers but if the user isn't generating new mouse
or key events, you can't tell if a modifier key has been
pressed/released, which can make for awkward interface experiences
with my current design. Clearly there are better ways to do things, I
was just experimenting and curious.
best,
wes -
On 26/12/2008, at 7:23 PM, Wesley Smith wrote:>
> Mainly because I'd like to be able to control various animating
> behaviors via key modifiers but if the user isn't generating new mouse
> or key events, you can't tell if a modifier key has been
> pressed/released, which can make for awkward interface experiences
> with my current design. Clearly there are better ways to do things, I
> was just experimenting and curious.
>
> best,
> wes
Er... when a modifier key is pressed, that's an NSEvent. Have a look
at this:
<http://developer.apple.com/qa/qa2007/qa1519.html>
HTH,
Ron -
On Dec 26, 2008, at 2:04 AM, Wesley Smith wrote:> Is there a way to know if a modifier key (shift, ctrl, option, cmd,
> etc) is pressed? Obviously, there's this:
> NSUInteger modifierFlags = [theEvent modifierFlags];
>
> but what if you need to know this information independent of an
> NSEvent? Anyway to get it? So far I haven't seen anything
> encouraging in the docs.
Depending on the context [[NSApp currentEvent]modifierFlags] may work
for you.
Gerd -
Thanks, works like a charm.
wes
On Fri, Dec 26, 2008 at 5:10 AM, Ron Fleckner
<ronfleckner...> wrote:>
> On 26/12/2008, at 7:23 PM, Wesley Smith wrote:
>>
>> Mainly because I'd like to be able to control various animating
>> behaviors via key modifiers but if the user isn't generating new mouse
>> or key events, you can't tell if a modifier key has been
>> pressed/released, which can make for awkward interface experiences
>> with my current design. Clearly there are better ways to do things, I
>> was just experimenting and curious.
>>
>> best,
>> wes
>
> Er... when a modifier key is pressed, that's an NSEvent. Have a look at
> this:
> <http://developer.apple.com/qa/qa2007/qa1519.html>
>
> HTH,
>
> Ron
> -
Wesley Smith (<wesley.hoke...>) on 2008-12-26 3:04 AM said:> Is there a way to know if a modifier key (shift, ctrl, option, cmd,
> etc) is pressed? Obviously, there's this:
> NSUInteger modifierFlags = [theEvent modifierFlags];
>
> but what if you need to know this information independent of an
> NSEvent? Anyway to get it? So far I haven't seen anything
> encouraging in the docs.
There's GetCurrentKeyModifiers(), which is superbly documented in
CarbonEventsCore.h. But sticking with NSEvent, if you can, if probably
better.
Sean -
On Dec 31, 2008, at 11:36 AM, Sean McBride wrote:> Wesley Smith (<wesley.hoke...>) on 2008-12-26 3:04 AM said:
>
>> Is there a way to know if a modifier key (shift, ctrl, option, cmd,
>> etc) is pressed? Obviously, there's this:
>> NSUInteger modifierFlags = [theEvent modifierFlags];
>>
>> but what if you need to know this information independent of an
>> NSEvent? Anyway to get it? So far I haven't seen anything
>> encouraging in the docs.
>
> There's GetCurrentKeyModifiers(), which is superbly documented in
> CarbonEventsCore.h. But sticking with NSEvent, if you can, if
> probably
> better.
There's really nothing wrong with relying upon certain Carbon APIs.
If or when Apple ever removes Carbon, I foresee APIs moving to new
homes.
It's not like the current system has two shared libraries (Carbon/
Cocoa) and when Carbon goes, all APIs go with it. In many cases,
Carbon APIs are just wrappers over lower-level code.
If there are key pieces of functionality that you can do in Carbon,
but not Cocoa, definitely file enhancement requests to add those APIs
to Cocoa.
___________________________________________________________
Ricky A. Sharp mailto:<rsharp...>
Instant Interactive(tm) http://www.instantinteractive.com -
Ricky Sharp (<rsharp...>) on 2008-12-31 1:21 PM said:>>> Is there a way to know if a modifier key (shift, ctrl, option, cmd,
>>> etc) is pressed? Obviously, there's this:
>>> NSUInteger modifierFlags = [theEvent modifierFlags];
>>>
>>> but what if you need to know this information independent of an
>>> NSEvent? Anyway to get it? So far I haven't seen anything
>>> encouraging in the docs.
>>
>> There's GetCurrentKeyModifiers(), which is superbly documented in
>> CarbonEventsCore.h. But sticking with NSEvent, if you can, if
>> probably
>> better.
>
> There's really nothing wrong with relying upon certain Carbon APIs.
> If or when Apple ever removes Carbon, I foresee APIs moving to new
> homes.
Sticking with NSEvent is better not because GetCurrentKeyModifiers() is
Carbon, but because of the nature of GetCurrentKeyModifiers(). Please
read the excellent comments in the header that I mentioned. The OP was
vague on his goals/needs, so GetCurrentKeyModifiers() maybe appropriate.
Sean


