DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Benoit has posted 48 posts at DZone. View Full User Profile

Fix Double Keypress With Safari

02.25.2007
| 4190 views |
  • submit to reddit
        Fix a bug with the event keypress ( double keypress ... ) with Safari ( Mac OSX Tiger )
var v_fixDblKey = 0;
function fixDblKey() {
	if (v_fixDblKey != 0) {
		return true;
	} else {
		v_fixDblKey = setTimeout('v_fixDblKey = 0;', 10);
		return false;
	}
}
Sample
...
inputOnkeyup : function(event) {
	if (fixDblKey()) { return; }
	switch (event.keyCode) {
		case 38 : /* up */
			break
		case 40 : /* down */
			break;
		case 37 : /* left */
			break;
		case 39 : /* right */
			break;
		case  9 : /* tab */
			break;
		case 13 : /* enter */
			break;
	}
}
...