Javascript key recognition

Curiosity

Registered
I have a Javascript file that detects key codes, but it is set to react to Windows keyboard keys. How would I adapt it to work with a Mac keyboard?
Code:
	// Hotkeys
	document.addEventListener('keydown', function(e){
		if(e.shiftKey && !e.ctrlKey && e.altKey){
			switch(e.keyCode){
				// Edit styles with Alt+Shift+E
				case 69: editStyles(); break;
				// Unblock elements with Alt+Shift+U
				case 85: unblockEle(); break;
				 // Block element with Alt+Shift+B
				case 66: blockEle(); break;
				// Unblock latest element with Alt+Shift+L
				case 76: unblockEle(true); break;
				 // Block elements (don't use nth-child) with Alt+Shift+W
				case 87: blockEle(true); break;
			}
		}
	}, false);
The Alt key is the problem. I guess the Alt/Option key on a Mac keyboard is not the same as the Alt key for Windows. What name would I give to have that key recognized?
 
I like the tester at the end of the page. How would I alter the javascript code to use the keycode directly? Apparently, Shift is keycode 16 and Option is keycode 18. What one is supposed to do is use Shift-Alt-B to do something, and Shift-Alt-U to do something else. I also wonder if the whole javascript is unworkable on a Mac.
 
It looks like standard characters and numbers (among other things) are detected on 'keypress', 'keydown', and 'keyup' while modifier keys on the Mac (like command, option, control, etc.) are only detected on 'keydown' and 'keyup' (not 'keypress') -- at least on my Mac under Safari.

Javascript works nicely on a Mac -- I program heavy Javascript day in and out for Macs and other operating systems. Never done much with keypresses, though, so I can't be of much help there.
 
Well, thanks for the reference anyway. I like the tester, and have bookmarked the link. I found a button that will launch the blocker (which is what the javascript is supposed to do). It works, so I guess I can forget about the keypresses.
 
Back
Top