[futurebasic] Re: [FB] GetKey

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : October 2008 : Group Archive : Group : All Groups

From: Robert Purves <listrp@...>
Date: Wed, 22 Oct 2008 15:45:33 +1300
Mark Chappell wrote:

> It doesn't exactly fail.  As far as I can tell, it simply maps  
> differently on intel versus PPC.   Let me do the remap and see if it  
> is consistent on different intel machines.
>
> As you may know, the getkeys call puts the key code into an 8  
> element array ( elements numbered 0-7).

No. GetKeys() puts 128 bits into the address specified. If you treat  
this as 16 x 1 byte, no endian issues arise.

Robert P.


'---------------------
/*
KeyMap and Scan Codes
This program shows the KeyMap returned by GetKeys, and the
scan code for keys pressed. Scan codes are useful if
you want to test for key-down status with this routine:

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 // 128-bit structure
call GetKeys( keys(0) )
end fn = -((keys(k>>3) >> (k and 7)) and 1)

The most useful codes are for modifier keys:
_cmdKeyCode      = 0x37
_shiftKeyCode    = 0x38
_capsLockKeyCode = 0x39
_optKeyCode      = 0x3A
_ctrlKeyCode     = 0x3B

Scan codes are unrelated to ASCII character codes.

Robert P.   June 2001
*/

defstr byte

local fn ShowKeyMapAndScanCodes
'~'1
dim k as long
dim keys(15) as char // 128-bit structure

call GetKeys( @keys(0) )
color = _zBlack
print @(1, 3) "Key codes:";
for k = 0 to 127
long if ((keys(k>>3) >> (k and 7)) and 1)
print k; " (0x" hex$( k ) ") ";
end if
next

cls page

for k = 0 to 127
color = _zBlack
call MoveTo( 50 + k*4, 15 )
call Line( 0, -1)
long if ((keys(k>>3) >> (k and 7)) and 1)
color = _zBlack
xelse
color = _zWhite
end if
call Line( 0, -10)
next
end fn

window 1, "KeyMap and Scan Codes", (0,0)-(620,80), _docNoGrow
text ,,, _srcCopy
do
fn ShowKeyMapAndScanCodes
HandleEvents
until fn Button
'---------------------