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)) {
source share