Skip to content

Fixing keyTyped() for dev-2.0 branch #7809

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

Merged
merged 1 commit into from
May 13, 2025

Conversation

perminder-17
Copy link
Collaborator

@perminder-17 perminder-17 commented May 13, 2025

Resolves #7805

Changes:

Screenshots of the change:

PR Checklist

@perminder-17 perminder-17 linked an issue May 13, 2025 that may be closed by this pull request
17 tasks
@perminder-17 perminder-17 merged commit cd80ae3 into dev-2.0 May 13, 2025
5 checks passed
@perminder-17 perminder-17 deleted the keyTyped()-for-dev-2.0-branch branch May 13, 2025 21:50
@AhmedMagedC
Copy link
Contributor

Hi, @perminder-17
may i know why did you choose to use e.repeat? as i said in my PR e.repeat always results in False value, the main solution was to allow for the same char to be pressed consecutively more than once while preventing from printing the same char if the user holds down the key.

@perminder-17
Copy link
Collaborator Author

perminder-17 commented May 14, 2025

Hi @AhmedMagedC , Really thanks for raising your concerns, these discussions are really very appreciated in PROCESSING FOUNDATION so if anything goes wrong could be fixed :).

e.repeat is to distinguish a genuine second tap (where repeat stays false) from the flood of auto-repeat events you get when the key is held down. i.e. if you press key 2 times, it is false but if you hold the key for 2-3 seconds it should be true.

Here's the screenshot from the mdn docs

Screenshot from 2025-05-14 16-01-55

Can you please confirm what you get when you hold any key for maybe 3-4 seconds, do you get e.repeat as true?

If that's again false, can you please let me know what browser and version you using? here's the browser compatibility written " https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/repeat?utm_source=chatgpt.com " maybe due to compatibility issue you could be getting always false?

Also, in your PR i.e. #7808 as I can see you are first setting isKeyRepeated variable to true only when e.repeat is true. So it means you are using e.repeat any way or the other to check stuffs.

In your PR, it's something like ;

  if (e.repeat) {
     this._setProperty('isKeyRepeated', true);  // isKeyRepeated is used further.
    return;
  }

I am really sorry if I am not referring to the same thing you are talking about? Can you please let me know if I am clear to explain the use of e.repeat, or maybe feel free to raise any other concerns you have. :)

@AhmedMagedC
Copy link
Contributor

Hi @perminder-17, the issue is that e.repeat results in false even if you hold down the key,

but when i tried to print the e.repeat value in fn._onkeydown = function(e) {} e.repeat gives true if you hold down, but it gives always false for fn._onkeypress = function(e) {}

i tested on chrome & avast & Microsoft edge

@perminder-17
Copy link
Collaborator Author

e.repeat value in fn._onkeydown = function(e) {} e.repeat gives true if you hold down, but it gives always false for fn._onkeypress = function(e) {}

Okay, thanks for reporting.

But I also checked on firefox and chrome (at linux) and everything was working correctly as expected. This looks like could be a browser specific issue. Someone previously had a similar issue with this. : https://stackoverflow.com/questions/53200698/onkeypress-repeat-always-returns-false-in-some-browsers

Workaround could be, maybe we will move e.repeat in fn.onkeyDown and then probably use that in fn.onkeyPress.
Do you agree with this @davepagurek or could be a different workaround for it. I think its a browser specific issue, are you also able to reproduce the same in your system as well?

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.

keyTyped function ignores last key typed
2 participants