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

Improve keyboard handling #14

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

nagygeri97
Copy link

  • Ensure that pressing F1-F12 doesn't type it's value
  • Start and stop player with space in practice mode
  • Start and stop first unsolved player in daily mode

@@ -379,7 +379,7 @@ document.getElementById("keyboard-cont").addEventListener("click", (e) => {
document.addEventListener("keyup", (e) => {

let pressedKey = String(e.key)
let found = pressedKey.match(/[a-z]/gi)
let found = pressedKey.match(/^[a-z]$/gi)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering if this is the best way to check this though. Regex are relatively costly and slow for something like this, wouldn't it be more efficient just check that the input is within the range a to z, which causes JS to compare the ascii key code? i.e. pressedKey >= 'a' && pressedKey <= 'z'.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no, not really. regex isnt that costly. if we really needed to change it than something like

pressedKey.toUpperCase() != char.toLowerCase() || pressedKey.codePointAt(0) > 127

@nagygeri97 nagygeri97 force-pushed the key-handling-improvements branch from ef60d89 to fc861bb Compare January 28, 2024 21:15
* Ensure that pressing F1-F12 doesn't type it's value
* Start and stop player with space in practice, spelloff and youtube modes
* Start and stop first unsolved player with space in daily mode
@nagygeri97 nagygeri97 force-pushed the key-handling-improvements branch from fc861bb to 5928baa Compare January 28, 2024 21:20
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 this pull request may close these issues.

3 participants