[futurebasic] Re: GetCurrentKeyModifiers

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : June 2003 : Group Archive : Group : All Groups

From: Ken Shmidheiser <kshmidheiser@...>
Date: Fri, 13 Jun 2003 10:50:57 -0400
Here is a rewritten version of the GetCurrentKeyModifiers example 
that more closely complies with Apple's documentation. Apparently 
some keyboards distinguish between left and right modifier keys and 
this example would handle that.

Suggestions are always welcome.

Ken

toolbox fn GetCurrentKeyModifiers = UInt32

begin enum
_activeFlagBit      =  0
_btnStateBit        =  7
_cmdKeyBit          =  8
_shiftKeyBit        =  9
_alphaLockBit       = 10
_optionKeyBit       = 11
_controlKeyBit      = 12
_rightShiftKeyBit   = 13
_rightOptionKeyBit  = 14
_rightControlKeyBit = 15
end enum

begin enum
_activeFlagMod      = 1 << _activeFlagBit
_btnStateMod        = 1 << _btnStateBit
_cmdKeyMod          = 1 << _cmdKeyBit
_shiftKeyMod        = 1 << _shiftKeyBit
_alphaLockMod       = 1 << _alphaLockBit
_optionKeyMod       = 1 << _optionKeyBit
_controlKeyMod      = 1 << _controlKeyBit
_rightShiftKeyMod   = 1 << _rightShiftKeyBit
_rightOptionKeyMod  = 1 << _rightOptionKeyBit
_rightControlKeyMod = 1 << _rightControlKeyBit
end enum

dim as integer whichKey, oldKey : oldKey = -1
dim as rect    r

setrect( r, 0, 0, 200, 100 )
window 1, "Modifier Keys", @r
setrect( r, 20, 20, 180, 80 )
text _applFont,10
edit field 1, "" , @r, _statFramed, _centerJust

do
whichKey = fn GetCurrentKeyModifiers
long if oldKey != whichKey
oldKey = whichKey
if whichKey == _activeFlagMod       then edit$(1) = "" else edit$(1) = ""
if whichKey and _cmdKeyMod          then edit$(1,_maxInt,_maxInt) = " 
Comand key "
if whichKey and _shiftKeyMod        then edit$(1,_maxInt,_maxInt) = " 
Shift key "
if whichKey and _alphaLockMod       then edit$(1,_maxInt,_maxInt) = " 
Caps lock "
if whichKey and _optionKeyMod       then edit$(1,_maxInt,_maxInt) = " 
Option key "
if whichKey and _controlKeyMod      then edit$(1,_maxInt,_maxInt) = " 
Control key "
if whichKey and _rightShiftKeyMod   then edit$(1,_maxInt,_maxInt) = " 
Right Shift key "
if whichKey and _rightOptionKeyMod  then edit$(1,_maxInt,_maxInt) = " 
Right Option key "
if whichKey and _rightControlKeyMod then edit$(1,_maxInt,_maxInt) = " 
Right Control key "
end if
handleevents
until 0
end