[futurebasic] Re: [FB] Test of alt key

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

From: George Wood <gwendalwood@...>
Date: Sat, 09 Jun 2001 21:30:43 +0000
on 06/06/2001 11:27 PM, Robert Purves at robert.purves@...
wrote:

>>> Here's a politically correct and Apple-blessed method that should continue
>>> to work even under the forthcoming MacOS XI    :-)
>>> 
>>> local fn IsOptKeyDown
>>> // _zTrue if option (alt) key is pressed, else _false
>>> dim keys(7) as short
>>> call GetKeys( keys(0) )
>>> end fn = ( (keys(3) and 4) == 4 )
> 
>> What is needed to have this also indicate Command key, Control Key, etc?
>> Caps lock too? Shift Key?  This is one area that I have found many fn's
>> for, but none of them work consistently for all cases.  Drives me bonkers.
> 
> See below for some general and evidently reliable methods.
> 
> Robert P.
> 
> 
> '----complete FB^3 program-------
> /*
> Modifier keys
> 
> There are two methods for finding the state of the modifier keys.
> You can examine the .modifiers field of the event record in various
> ways. Or you can test the relevant bits of a KeyMap returned
> by GetKeys. The GetKeys method is independent of HandleEvents.
> 
> A subtle difference between the two methods is that an event reflects
> the modifier key status at the time the event was queued by the Event
> Manager, i.e. at some time in the (usually recent) past, whereas GetKeys
> gives the status _now_. Theoretically then, the two methods could
> give different results.
> 
> Robert P.    7 June 2001
> */
> 
> '~Event modifiers method
> 
> // The modifiers field is set correctly for on low level events,
> // including null events. I assume, but haven't checked, that it
> // is also correct for high-level events such as AppleEvents.
> local fn DoEvent
> dim ev as ^EventRecord
> ev = event // pointer to event record
> print @(1, 5) "From event.modifiers"
> print (ev.modifiers and _cmdKey%)     != 0,
> print (ev.modifiers and _shiftKey%)   != 0,
> print (ev.modifiers and _alphaLock%)  != 0,
> print (ev.modifiers and _optionKey%)  != 0,
> print (ev.modifiers and _controlKey%) != 0
> end fn
> 
> /*
> // Alternative syntax to above
> local fn DoEvent
> dim ev as pointer
> ev = event // pointer to event record
> print @(1, 5) "From event.evtmeta%"
> print (ev.evtmeta% and _cmdKey%)     != 0,
> print (ev.evtmeta% and _shiftKey%)   != 0,
> print (ev.evtmeta% and _alphaLock%)  != 0,
> print (ev.evtmeta% and _optionKey%)  != 0,
> print (ev.evtmeta% and _controlKey%) != 0
> end fn
> */
> 
> /*
> // Alternative method to above
> local fn DoEvent
> dim modifiers as short
> modifiers = event% // modifiers field
> print @(1, 5) "From event%"
> print (modifiers and _cmdKey%)     != 0,
> print (modifiers and _shiftKey%)   != 0,
> print (modifiers and _alphaLock%)  != 0,
> print (modifiers and _optionKey%)  != 0,
> print (modifiers and _controlKey%) != 0
> end fn
> */
> 
> '~GetKeys method
> 
> local fn IsKeyDown( k as char )
> // k is a keyboard scan code, 0-127
> // Return _zTrue if key is pressed, else _false
> dim keys(15) as char
> call GetKeys( keys(0) )
> end fn = ( ( (keys(k>>3) >> (k and 7)) and 1 ) != 0 )
> 
> _cmdKeyCode      = 0x37
> local fn IsCmdKeyDown // command (Apple)
> end fn = fn IsKeyDown( _cmdKeyCode )
> 
> _shiftKeyCode    = 0x38
> local fn IsShiftKeyDown // shift
> end fn = fn IsKeyDown( _shiftKeyCode )
> 
> _capsLockKeyCode = 0x39
> local fn IsCapsLockKeyDown // caps lock
> end fn = fn IsKeyDown( _capsLockKeyCode )
> 
> _optKeyCode      = 0x3A
> local fn IsOptKeyDown // option (alt)
> end fn = fn IsKeyDown( _optKeyCode )
> 
> _ctrlKeyCode     = 0x3B
> local fn IsCtrlKeyDown // control
> end fn = fn IsKeyDown( _ctrlKeyCode )
> 
> '~Main program
> 
> window 1, "Modifier Key Status"
> text ,,, _srcCopy
> on event fn DoEvent
> do
> print @(1, 1) "Direct from GetKeys"
> print @(1, 2) "command", "shift", "caps lock", "option", "control"
> print fn IsCmdKeyDown, fn IsShiftKeyDown, fn IsCapsLockKeyDown,
> print fn IsOptKeyDown, fn IsCtrlKeyDown
> HandleEvents // try commenting this out
> until fn Button
> '-------------------------------
> 
> 
> 
> 
> --
> To unsubscribe, send ANY message to <futurebasic-unsubscribe@...>
> 
> 
All of these look great, however, I need a routine that will function like
command period. without the consequences of a commandperiod such as with
tron/troff. In other words, how to test if the commandkey is down and then a
certain key (such as period) is also down.Thanks
GeoWood