Return to Snippet

Revision: 16965
at August 19, 2009 11:22 by MoogPHP


Initial Code
function trap(e) {
	if (!e) {
		e = event;
		e.which = e.keyCode;
	}
	try {
		modifierKey = e.ctrlKey || e.altKey || e.metaKey;
	}
	catch(e) {
		modifierKey = false;
	}
	return modifierKey || e.which == 0;
}
function keys(key) {
	if (!key) {
		key = event;
		key.which = key.keyCode;
	}
	if (key.which == 84) {
		//toggle();
		return;
	}
		switch (key.which) {
			case 32: // spacebar
			case 34: // page down
			case 39: // rightkey
			case 40: // downkey
				// Do something
				break;
			case 33: // page up
			case 37: // leftkey
			case 38: // upkey
				// Do something
				break;
			case 36: // home
				// Do something
				break;
			case 35: // end
				// Do something
				break;
			case 27: // escape
			case 81: // q
				// Do something
				break;
		}

	return false;
}

function keyCap() {
	document.onkeypress = trap;
	document.onkeyup = keys;
}

Initial URL
http://rmhh.co.uk/ascii.html

Initial Description

                                

Initial Title
Key stroke capture

Initial Tags

                                

Initial Language
JavaScript