home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / sys / mac / programm / 18649 < prev    next >
Encoding:
Text File  |  1992-11-19  |  3.1 KB  |  77 lines

  1. Newsgroups: comp.sys.mac.programmer
  2. Path: sparky!uunet!cs.utexas.edu!torn!nott!bnrgate!bmers95!usenet
  3. From: ross@bnr.ca (Ross Brown)
  4. Subject: Re: Determining modifier key status without an event record
  5. Message-ID: <1992Nov19.160324.14279@bmers95.bnr.ca>
  6. Sender: usenet@bmers95.bnr.ca
  7. Organization: Bell-Northern Research Ltd.
  8. References: <Bxy4IM.25J@news.udel.edu>
  9. Date: Thu, 19 Nov 1992 16:03:24 GMT
  10. Lines: 65
  11.  
  12. In article <Bxy4IM.25J@news.udel.edu> kurisuto@chopin.udel.edu (Sean J. Crist)
  13. writes:
  14. >The orthodox method of determining the status of the modifier keys is
  15. >by looking at an event record.  The modifier bits are even set correctly
  16. >for null events, so within the event loop, it is always possible to
  17. >determine the status of the modifier keys.
  18. >
  19. >However, I need to find the status of the modifier keys in contexts
  20. >where no reliable event record is available.  Specifically:
  21. >
  22. >1.  I want to know what the status of the modifier keys at the earliest
  23. >    possible moment when the application starts up.  I have an optional
  24. >    short-cut which is invoked if the user holds down the command key
  25. >    when starting the application.
  26. >
  27. >2.  I want to know what modifier keys are down when the user has selected
  28. >    something from a menu.  The original mousedown event in the menu
  29. >    bar is not a reliable source, because the user might have pressed
  30. >    the mod keys after clicking the mouse and while viewing the menus.
  31. >    (I have another shortcut which I want to invoke if the user holds
  32. >    down certain modifier keys while making certain menu selections).
  33. >
  34. >Is there some way to find out the status of the mod keys in these contexts?
  35. >If the answer is something really risky and unsupported, I'd be more
  36. >inclined just to scrap these shortcuts, but I'd like to make them
  37. >available if it's possible.
  38.  
  39. The _GetKeys trap works for me in such cases.  It's well documented.  I have
  40. noticed that it (or the keyboard, maybe) wimps out when more than about 4 keys
  41. are pressed at once - it doesn't sense them all.  But for modifier keys, it
  42. should work fine.  Code snippet follows.
  43.  
  44. #define leftOptionKeyCode   0x3A    /* I don't think */
  45. #define rightOptionKeyCode  0x3D    /* that these are */
  46. #define commandKeyCode      0x37    /* defined anywhere. */
  47.  
  48. Boolean IsKeyDown( KeyMap keyMap, short keyCode )
  49. {
  50.     if( ( (char *) keyMap )[ keyCode >> 3 ] & ( 1 << ( keyCode & 0x7 ) ) )
  51.         return true;
  52.     else
  53.         return false;
  54. }
  55.  
  56. Boolean IsOptionKeyDown( void )
  57. {
  58.     KeyMap  keyMap;
  59.     GetKeys( keyMap );
  60.     return IsKeyDown( keyMap, leftOptionKeyCode ) || IsKeyDown( keyMap,
  61. rightOptionKeyCode );
  62. }
  63.  
  64. Boolean IsCommandKeyDown( void )
  65. {
  66.     KeyMap  keyMap;
  67.     GetKeys( keyMap );
  68.     return IsKeyDown( keyMap, commandKeyCode );
  69. }
  70.  
  71. ==============================================================================
  72. Ross Brown, Dept. 7C22  < Bell-Northern Research     >  Just the facts, ma'am.
  73. Advisor, Telemgmt Svcs  < P. O. Box 3511, Station C  >  We don't care whose
  74. ross@bnr.ca             < Ottawa, ON, Canada K1Y 4H7 >  opinions yours aren't.
  75. ==============================================================================
  76.  
  77.