GetKeys
GetKeys
Get a map of the state (up or down) of all keys KeyMap theKeys ; receives 16-byte binary map of key states GetKeys is a little-used alternative to awaiting a keyDown event. It fills a 16-byte (128-bit) structure with bits - each bit indicating the state of one
key.
theKeys is the address of a 16-byte KeyMap structure. Upon return, it is filled with binary data that indicates the current state of all keys. A
1 bit indicates that a key is currently down; a 0 indicates it is up.
Notes: Upon return, theKeys is laid out as 16 bytes. The order of the bits is in
MC68000 right-to-left within each byte. Thus, the BitTst function won't help here.
For instance, to see if the spacebar is currently down (scan code 0x31 or
49 decimal), first note that its bit will be in the 6th byte (( short)
49/8=6) then test with a mask in bit 1 (49%8=1) of that byte.
Rather than modify the KeyMap structure, you can just pass the address of an 16-byte buffer to GetKeys. For instance, the following function returns a Boolean value identifying if a specified key is currently pressed: short isPressed(unsigned short k )
// k = any keyboard scan code, 0-127
{
unsigned char km[16];
return ( ( km[k>>3] >> (k & 7) ) & 1);
}
See Keyboard Layouts for a depiction of the various Macintosh keyboards and the scan codes that correspond to bits in theKeys.
The maximum number of keys that can be down simultaneously is two
character keys plus any combination of the five modifier keys.