improved keycode handling