Better implementation of onKeyMoved() and improved testing