Solved random crashes coming from prolonged key press by addinga mutex on the critical part