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

Number key presses don't generate key objects. #5

Open
jprichardson opened this issue Mar 12, 2013 · 8 comments
Open

Number key presses don't generate key objects. #5

jprichardson opened this issue Mar 12, 2013 · 8 comments

Comments

@jprichardson
Copy link

If I follow the example and press 1 or any number on the keyboard, it is returned as ch but key is undefined. Is this intentional?

@davidvgus
Copy link

I'm also curious about this.

@lutzbickhardt
Copy link

in fact it concerns also all characters like ,.-#+*
a quick fix without setting meta and shift keys is as follows:

} else if (s.length === 1 && s >= 'A' && s <= 'Z') {
// shift+letter
key.name = s.toLowerCase();
key.shift = true;
/new/
} else if (s.length === 1 && (
(s >= '!' && s <= '@') ||
(s >= '[' && s < 'a') ||
(s >= '{' && s <= '~')
)) {
// meta+shift key setting ignored
key.name = s;
/new end/

@wyattbiker
Copy link

no fix forthcoming to handle all the keys? (including 0-9 and special cars?

@mas9612
Copy link

mas9612 commented Jan 11, 2016

Has this problem been solved?
In my program, numkey is recognized as undefined.

@StreetStrider
Copy link

@mappto, seemes that there's a bunch of fixes (and forks), none of them are 100% correct :D The most obvious fix is not bulletproof.

@naus3a
Copy link

naus3a commented Mar 18, 2016

in case someone is still wondering how to get numbers:

if(key){
//do your normal checks
...
}else{
var nn = Number(ch);
if(nn===0||nn===1||nn===2||nn===3||nn===4||nn===5||nn===6||nn===7||nn===8||nn===9){
//do your number based checks
}
}

@popeyebot
Copy link

Thanks for get the number, how to get ²&é"'(-è_çà)=,;:!?./§~#{[|`^@]}

@naus3a
Copy link

naus3a commented Nov 6, 2017

I did not try, but I imagine the approach would be similar: cast to char, or cast to int and check the ascii code.

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

Successfully merging a pull request may close this issue.

8 participants