[futurebasic] GetCurrentKeyModifiers

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

From: Ken Shmidheiser <kshmidheiser@...>
Date: Fri, 13 Jun 2003 08:31:14 -0400
In some recent experimentation, I discovered the 
GetCurrentKeyModifiers function which appears very simple to use.

I have written the following code snippet to demonstrate what happens 
when a single modifier key is pressed. However, when multiple 
modifier keys are simultaneously pressed their bit values are 
automatically added together and returned in a single integer by 

My question is: How would one go about parsing out from the returned 
integer just which modifier keys had been pressed? I guess I could 
build an exhaustive select case table, but there must be an easier 

GetCurrentKeyModifiers may have been discussed here before (I know 
Robert P. has shown us how to use GetKeys) and if so, please excuse 
this post. But my little peanut brain can't seem to recall this 
specific function for modifiers.

I'm posting this because modifier key implementation is a recurrent 
question to the list and this shows promise of an easy solution.


toolbox fn GetCurrentKeyModifiers = UInt32

begin enum
_waiting      =    0
_cmdMod       =  256
_shiftMod     =  512
_alphaLockMod = 1024
_optionMod    = 2048
_controlMod   = 4096
end enum

dim as integer whichKey
dim as rect    r

setrect( r, 0, 0, 200, 70 )
window 1, "Modifier Keys", @r
setrect( r, 20, 20, 180, 45 )
text _applFont,14
edit field 1, , @r, _statFramed, _centerJust

whichKey = fn GetCurrentKeyModifiers
select case whichKey
case _waiting      : edit$(1) = "Waiting"
case _cmdMod       : edit$(1) = "Comand key"
case _shiftMod     : edit$(1) = "Shift key"
case _alphaLockMod : edit$(1) = "Caps lock"
case _optionMod    : edit$(1) = "Option key"
case _controlMod   : edit$(1) = "Control key"
case else          : edit$(1) = str$( whichKey )
end select
until fn button