Re: detect control key
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.