On Mar 21, 2007, at 9:30 PM, Dr Gerard Hammond wrote:

> (Sorry if this is hits the list twice)
>
> Hi,
>
> Does anybody have a tested and working solution for detecting the
> CapsLock status on MacOS X?
>
> Searching the archives I found this suggestion:
>
>    #if TargetMacOS then
>      return Keyboard.AsyncKeyDown(&h39)
>    #endif
>
> but this didn't work for me (on my MacBookPro)
>
> Any other suggestion?

Something in an HID Device should be able to get LED status as well  
as what I suggest here

A declare into this GetCurrentKeyModifiers
Returns the current state of the keyboard modifier keys.

UInt32 GetCurrentKeyModifiers ();
Parameters


Return Value

        A bit mask indicating which keyboard modifier keys are pressed. See  
"Event Modifier Constants" for a list of possible values.

Discussion

        GetCurrentKeyModifiers provides a more convenient way to get the  
modifier key state than calling GetNextEvent. It returns a value whose

        individual bits indicate which keyboard modifier keys are currently  
being pressed. You can test for the Caps Lock, Shift, Control,  
Option, and

        Command keys using the “Event Manager Reference” defined by the  
Event Manager.

Availability

        Supported in Carbon. Available in CarbonLib 1.0 and later.
        Available in Mac OS X 10.0 and later.
        Declared In Events.h



Function IsCapsDown() as Boolean

   '/* modifiers */
   'activeFlagBit                 = 0,    /* activate? (activateEvt  
and mouseDown)*/
   'btnStateBit                   = 7,    /* state of button?*/
   'cmdKeyBit                     = 8,    /* command key down?*/
   'shiftKeyBit                   = 9,    /* shift key down?*/
   'alphaLockBit                  = 10,   /* alpha lock down?*/
   'optionKeyBit                  = 11,   /* option key down?*/
   'controlKeyBit                 = 12,   /* control key down?*/
   'rightShiftKeyBit              = 13,   /* right shift key down?*/
   'rightOptionKeyBit             = 14,   /* right Option key down?*/
   'rightControlKeyBit            = 15    /* right Control key down?*/
   '
   'activeFlag = 1 << activeFlagBit,
   const btnState = 128 'btnState = 1 << btnStateBit,
   const cmdKey = 256 'cmdKey = 1 << cmdKeyBit,
   const shiftKey = 512 'shiftKey = 1 << shiftKeyBit,
   const alphaLock = 1024 'alphaLock = 1 << alphaLockBit, (OR 1024)
   const optionKey = 2048 'optionKey = 1 << optionKeyBit,
   const controlKey = 4096 'controlKey = 1 << controlKeyBit,
   const rightShiftKey = 8192 'rightShiftKey = 1 << rightShiftKeyBit,
   const rightOptionKey = 16384 'rightOptionKey = 1 <<  
rightOptionKeyBit,
   const rightCnotrolKey = 32768 'rightControlKey = 1 <<  
rightControlKeyBit

   #if TargetMacOS then
     #if TargetMachO
       Declare function GetCurrentKeyModifiers Lib "Carbon" () as  
Integer
     #elseif TargetCarbon then
       Declare function GetCurrentKeyModifiers lib "CarbonLib" () as  
Integer
     #endif
   #endif

   dim result as integer

   result = GetCurrentKeyModifiers

   return bitwise.BitAnd(result ,alphaLock) > 0


_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives:
<http://support.realsoftware.com/listarchives/lists.html>

Reply via email to