improved key handling using keycode and .fromcharcode methods