If you press a key such as Ctrl the code gets a bitfield with a high bit set so when the key code is used as an index it produces an out of range error. Thank you AddressSanitizer!