improved onkeydown and onkeyup event functions