Keep track of keys pressed, synthesize release events when focus is lost.
Closes #2375.