Stateful DOM keyboard handler for use in games