Learn Create Your Own Split Screen

Next Page

Now we do addEventListener and add some useful logic to our handler:
function MyKeyDownHandler (MyEvent) { if (MyEvent.keyCode == 39) {x_pos = x_pos + 10;} // right if (MyEvent.keyCode == 40) {y_pos = y_pos + 10;} // down }

The keyCodes are special numbers that indicate particular keys.
Notice that you can drive your cat down and to the right, but not up or left.

(You will need to click on the canvas with your mouse before it gets the keystrokes)

Knowing that the keyCode for left is 37 and up is 38, now try to alter the program to also let the cat drive in those directions.