Factor out keydown enter key event detection logic

/cc @GaryJones