• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Option key state
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Option key state


  • Subject: Re: Option key state
  • From: David Remahl <email@hidden>
  • Date: Mon, 11 Feb 2002 18:46:07 +0100

> Hello,
> I need to test whether the option key is being held down or not when my
> application is launching. I only know how to check the option key's state
> from an NSEvent, but I don't really have one. I need to check the option
> key's state in the following method delegated by NSApplication.
>
> - (BOOL)application:(NSApplication*)anApplication
> openFile:(NSString*)aFileName
> {
> if (appIsLaunching) {
> wasLaunchedWithDocument = YES;
> // check here for option key's state
> }
> [self doSomeThing:[NSArray arrayWithObject:aFileName]];
> return YES;
> }
>
> Thanks! And I assume the name for the option key's keymask is
> "NSAlternateKeyMask"?
> -Josh Aas

Here is a category for NSEvent which uses Carbon to determine the state of
various modifiers. You could have searched the archives and found me asking
the same thing and getting this as the answer. Anyway, now is my chance to
repay that favour to the community.

-----NSEvent-CarbonAdditions.h------

#import <Carbon/Carbon.h>
#import <AppKit/AppKit.h>

@interface NSEvent (ModifierKeys)
+ (BOOL) isControlKeyDown;
+ (BOOL) isControlKeyDown;
+ (BOOL) isOptionKeyDown;
+ (BOOL) isCommandKeyDown;
+ (BOOL) isShiftKeyDown;
@end

-------------------------------------
-------NSEvent-CarbonAdditions.m-----

#import "NSEvent-CarbonAdditions.h"

@implementation NSEvent (ModifierKeys)

+ (BOOL) isControlKeyDown
{
return (GetCurrentKeyModifiers() & controlKey) != 0;
}

+ (BOOL) isOptionKeyDown
{
return (GetCurrentKeyModifiers() & optionKey) != 0;
}

+ (BOOL) isCommandKeyDown
{
return (GetCurrentKeyModifiers() & cmdKey) != 0;
}

+ (BOOL) isShiftKeyDown
{
return (GetCurrentKeyModifiers() & shiftKey) != 0;
}

@end
------------------------------------
_______________________________________________
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.

References: 
 >Option key state (From: Josh Aas <email@hidden>)

  • Prev by Date: Re: Double call of awakeFromNib on custom view
  • Next by Date: Re: Option key state
  • Previous by thread: Option key state
  • Next by thread: Re: Option key state
  • Index(es):
    • Date
    • Thread