Detecting Keyboard Click Event

When handling a click event, how do you tell if it’s from keyboard enter key or mouse click? Use a keydown event to set up detection before the click event is called:

var ENTER_KEY = 13;
var isKeyEvent = false;

$('.my-elem')
	.on('keydown', myElem_Key)
	.on('click', myElem_Click)
;

var myElem_Key = function(e) {
	var key = e.keyCode || e.which;
	if (key == ENTER_KEY) {
		isKeyEvent = true;
	}
}

var myElem_Click = function(e) {
	if (isKeyEvent) {
		// Handle key event click.
		isKeyEvent = false;
	}
}

The key event can be tied to multiple elements and the callback used as a pass-through for detection.

Sand Between My Toes

All of my reprise and expectation
Tangled in my lies of omission
Brandished in my curt confession
Sounding broken chords to hear
Your requite
Your reciprocation.
Hoping
Your face
Your voice
Your elegance
This persistence.

Telling The Hour

Punish me with the cruelest summer.
Terrify me with silence.
Make me desperate.
Let me wake alone, make me cry rivers.
You can rest your head at night
Knowing I deserved this.

Like flies in a jar,
I am mostly harmless.
Except for this vanishing hour of darkness.

Mount Moriah