keyCode which although deprecated is at least widely supported. For my
limited use case (space and enter keys) the behaviour seems to be consistent
across browsers. If you need to allow for more edge cases you can of course
extend this example further.