home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.sys.mac.programmer
- Path: sparky!uunet!cs.utexas.edu!torn!nott!bnrgate!bmers95!usenet
- From: ross@bnr.ca (Ross Brown)
- Subject: Re: Determining modifier key status without an event record
- Message-ID: <1992Nov19.160324.14279@bmers95.bnr.ca>
- Sender: usenet@bmers95.bnr.ca
- Organization: Bell-Northern Research Ltd.
- References: <Bxy4IM.25J@news.udel.edu>
- Date: Thu, 19 Nov 1992 16:03:24 GMT
- Lines: 65
-
- In article <Bxy4IM.25J@news.udel.edu> kurisuto@chopin.udel.edu (Sean J. Crist)
- writes:
- >The orthodox method of determining the status of the modifier keys is
- >by looking at an event record. The modifier bits are even set correctly
- >for null events, so within the event loop, it is always possible to
- >determine the status of the modifier keys.
- >
- >However, I need to find the status of the modifier keys in contexts
- >where no reliable event record is available. Specifically:
- >
- >1. I want to know what the status of the modifier keys at the earliest
- > possible moment when the application starts up. I have an optional
- > short-cut which is invoked if the user holds down the command key
- > when starting the application.
- >
- >2. I want to know what modifier keys are down when the user has selected
- > something from a menu. The original mousedown event in the menu
- > bar is not a reliable source, because the user might have pressed
- > the mod keys after clicking the mouse and while viewing the menus.
- > (I have another shortcut which I want to invoke if the user holds
- > down certain modifier keys while making certain menu selections).
- >
- >Is there some way to find out the status of the mod keys in these contexts?
- >If the answer is something really risky and unsupported, I'd be more
- >inclined just to scrap these shortcuts, but I'd like to make them
- >available if it's possible.
-
- The _GetKeys trap works for me in such cases. It's well documented. I have
- noticed that it (or the keyboard, maybe) wimps out when more than about 4 keys
- are pressed at once - it doesn't sense them all. But for modifier keys, it
- should work fine. Code snippet follows.
-
- #define leftOptionKeyCode 0x3A /* I don't think */
- #define rightOptionKeyCode 0x3D /* that these are */
- #define commandKeyCode 0x37 /* defined anywhere. */
-
- Boolean IsKeyDown( KeyMap keyMap, short keyCode )
- {
- if( ( (char *) keyMap )[ keyCode >> 3 ] & ( 1 << ( keyCode & 0x7 ) ) )
- return true;
- else
- return false;
- }
-
- Boolean IsOptionKeyDown( void )
- {
- KeyMap keyMap;
- GetKeys( keyMap );
- return IsKeyDown( keyMap, leftOptionKeyCode ) || IsKeyDown( keyMap,
- rightOptionKeyCode );
- }
-
- Boolean IsCommandKeyDown( void )
- {
- KeyMap keyMap;
- GetKeys( keyMap );
- return IsKeyDown( keyMap, commandKeyCode );
- }
-
- ==============================================================================
- Ross Brown, Dept. 7C22 < Bell-Northern Research > Just the facts, ma'am.
- Advisor, Telemgmt Svcs < P. O. Box 3511, Station C > We don't care whose
- ross@bnr.ca < Ottawa, ON, Canada K1Y 4H7 > opinions yours aren't.
- ==============================================================================
-
-