• 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: detect control key
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: detect control key


  • Subject: Re: detect control key
  • From: Philip George <email@hidden>
  • Date: Mon, 29 Jul 2002 13:59:46 -0500

[1] Add Carbon framework to your project, preferably into the "Linked
Frameworks" group.

[2] Then add the following #include:

#include <Carbon/Carbon.h>

[3] Then add the following #defines (not necessary, but VERY
convenient):

#define mask_Shift 512
#define mask_Control 4096
#define mask_Option 2048
#define mask_Command 256

#define mask_ShiftControl 4608
#define mask_ShiftOption 2560
#define mask_ShiftCommand 768
#define mask_ControlOption 6144
#define mask_ControlCommand 4352
#define mask_OptionCommand 2304

#define mask_ShiftControlOption 6656
#define mask_ShiftControlCommand 4864
#define mask_ShiftOptionCommand 2816
#define mask_ControlOptionCommand 6400

#define mask_ShiftControlOptionCommand 6912


[4] Then at ANY time, you can query the state of the modifier keys
with:

int themask = GetCurrentKeyModifiers();


[5] Immediately after that, you can do something like:

if (themask==mask_Command) {
// do something if the Command key is held down
} else if (themask==mask_Control) {
// do something if the Control key is held down
} else if (themask==mask_ControlCommand) {
// do something if the Control key AND the Command key are
BOTH held down
}

Again, you don't have to use the #defines, but I find them helpful.

Cheers.

- Philip



On Monday, July 29, 2002, at 02:05 AM, Chong Hiu Pun wrote:

> *This message was transferred with a trial version of CommuniGate(tm)
> Pro*
> How can I detect the user is pressing the control key?
>
> Mr Chong
> _______________________________________________
> 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.
_______________________________________________
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.

  • Follow-Ups:
    • Re: detect control key
      • From: Nicholas Riley <email@hidden>
References: 
 >detect control key (From: "Chong Hiu Pun" <email@hidden>)

  • Prev by Date: Re: Carrots Vs. Sticks in Copy Protection
  • Next by Date: Double columns issue
  • Previous by thread: Re: detect control key
  • Next by thread: Re: detect control key
  • Index(es):
    • Date
    • Thread