Fix get_key_state performance issue