[was [FB] Re: futurebasic Digest 7 Jun 2001 09:00:41 -0000 Issue 1760] >I could use some enlightenment here. IM says that GetKeys returns a map of >the keyboard, but it looks as if only 8 key conditions are returned. How >does it know what keys we are interested in? > >Then in fn = ( (keys(3) and 4) == 4 ), what is the 3d key on he array, and >why are we interested in finding out if it contains a 4? > >Well I told you I was confused. :) GetKeys operates on a 128-bit KeyMap structure, each bit indicating the status of one key. In the posting you refer to, dim keys(7) as short is (7+1)*sizeof(short)*8 = 128 bits. A later posting had a more general routine in which dim keys(15) as char is (15+1)*sizeof(char)*8 = 128 bits. '-----complete FB^3 program--------- /* 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 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 '----------------- Robert P.