quickfix for direction keys

Quick fix for #5881 (BTW, action described in this issue cause a fault on windows).
Have some ideas about changing this function, but I will do it later (in separate PR).