Factored out keyboard state tracking