canvas-animation: Factor out inlined keydown code into separate methods.