Getting keyboard status using the GetKeys function

Does anyone know how to get the state of a key (press or not) with the GetKeys function? In other words, how to handle this function:

bool result = isPressed(kVK_LeftArrow); 

Thankyou.

0
source share
1 answer

The KeyMap type is an array of integers, but its real layout is a series of bits, one per key code. The bit number for a particular key is less than the virtual key code.

Since the bit shift is not valid for very large values ​​(for example, you cannot just ask the compiler to shift 74 bits), the KeyMap type KeyMap divided into 4 parts. You need to accept the virtual number key code and the integer division by 32 to find the correct integer for the bits; then take the remainder to find out which bit should be set.

So try the following:

 uint16_t vKey = kVK_LeftArrow; uint8_t index = (vKey - 1) / 32; uint8_t shift = ((vKey - 1) % 32); KeyMap keyStates; GetKeys(keyStates); if (keyStates[index] & (1 << shift)) { // left arrow key is down } 
+4
source

All Articles