Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Javascript Mac key recognition

Javascript Mac key recognition
Thread Tools
Curiosity
Senior User
Join Date: Jul 2006
Status: Offline
Reply With Quote
Oct 26, 2010, 06:45 PM
 
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?
     
numbers25
Banned
Join Date: Oct 2010
Status: Offline
Reply With Quote
Oct 27, 2010, 03:19 AM
 
Try to see if this post is what your are looking for:
JavaScript Madness: Keyboard Events
     
Curiosity  (op)
Senior User
Join Date: Jul 2006
Status: Offline
Reply With Quote
Oct 27, 2010, 06:29 PM
 
Thanks. Interesting article, but I wonder how much of it is current? The Option key should be the same as Alt, but it does not seem to work that way. I tried rearranging the keycodes to use the Command key with another key and the Shift-Cmd-E combination does something using ctrlKey. Apparently the Cmd key should be metaKey, but not with Opera.
Perhaps it is the whole Javascript that is not workable on a Mac. I wish I knew more about how that works. It works fine on Windows Opera.
     
numbers25
Banned
Join Date: Oct 2010
Status: Offline
Reply With Quote
Oct 28, 2010, 05:20 AM
 
unfortunately as i always say with Javascript is most try and error.
There's no standar you just have to browse and infinite number of pages until you find what you're looking for
     
   
 
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Top
Privacy Policy
All times are GMT -4. The time now is 11:02 PM.
All contents of these forums © 1995-2017 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.8 © 2000-2017, Jelsoft Enterprises Ltd.,