function advance(event) { if (event instanceof MouseEvent) { console.log('clicked'); } else if (event instanceof KeyboardEvent && event.keyCode === 13) { console.log('enter'); } } window.addEventListener('keypress', advance);