Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

incorrect keycodes #62

Closed
wayneashleyberry opened this issue Oct 16, 2012 · 4 comments
Closed

incorrect keycodes #62

wayneashleyberry opened this issue Oct 16, 2012 · 4 comments

Comments

@wayneashleyberry
Copy link

It seems keymaster is reporting invalid keycodes.

If i log e.which from jquery and keymaster the results are different, keymaster's being the uppercase version

$(body).on('keypress', function (e) {
console.log(e.which);
});
key('a', function (e, handler) {
console.log(e.which);
});
// hit's 'a' on keyboard
// 65
// 97

if you lookup those codes, jquery is return 'a' and keymaster is returning 'A'

@mimshwright
Copy link
Contributor

It looks like jQuery logs different codes depending on whether the shift key is pressed. So 'a' is 97 and 'A' is 65. I think keymaster is deliberately treating each "key" as a single code and separating out the modifier.

I would say it could potentially be more confusing to developers if 'a' and 'A' were treated as separate keys and this issue shouldn't be fixed for every case. However, I added a flag called ignoreCase which is set to true by default. If you set it to false, the lowercase keycodes will be used when the shift key is up and the uppercase keycodes will be used when shift is down.

@mimshwright
Copy link
Contributor

I spoke too soon. I found some bugs and will update when i fix.

@mimshwright
Copy link
Contributor

OK! Upon further investigation, I found that jQuery actually tries to 'normalize' the code for the 'which' property to make it consistent across browsers.

To determine which key was pressed, examine the event object that is passed to the handler function. While browsers use differing properties to store this information, jQuery normalizes the .which property so you can reliably use it to retrieve the key code. This code corresponds to a key on the keyboard, including codes for special keys such as arrows. For catching actual text entry, .keypress() may be a better choice.

So KeyMaster actually will give you different codes on different browsers. That makes this a cross-browser / jquery issue more than a KeyMaster issue.

If you want to differentiate between "a" and "A" in keymaster, you can add a callback for "a" or "shift + a" .

@wayneashleyberry
Copy link
Author

Closed due to inactivity.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants