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

Support for keyup/keydown for .on() events #5734

Closed
iamwyza opened this issue Aug 25, 2017 · 7 comments
Closed

Support for keyup/keydown for .on() events #5734

iamwyza opened this issue Aug 25, 2017 · 7 comments
Labels
feature good first issue Good for newcomers

Comments

@iamwyza
Copy link

iamwyza commented Aug 25, 2017

How to reproduce

  • Leaflet version I'm using:1.2
  • Browser (with version) I'm using: Chrome 60
  • OS/Platform (with version) I'm using: Win 10 1706
  • map.on() doesn't supprot keydown/keyup

What behaviour I'm expecting and which behaviour I'm seeing

Because keypress doesn't register inputs that don't render characters, keypress doesn't work for things like backspace or escape.

Minimal example reproducing the issue

map.on('keypress', function() { console.log('pressed!'); });
@mourner mourner added feature good first issue Good for newcomers labels Nov 8, 2018
@zivkaziv
Copy link

Hey, I would be happy to take this first issue:) If it's still open

@OrBin
Copy link
Contributor

OrBin commented Dec 2, 2018

Hi, I've just submitted a PR (#6421) adding the requested feature.

perliedman pushed a commit that referenced this issue Jan 14, 2019
* Added support for 'keydown' and 'keyup' events, as requested in issue #5734

* Added tests for 'keydown', 'keypress' and 'keyup' events binding and constified the key codes used in the test file
@OrBin
Copy link
Contributor

OrBin commented Jan 14, 2019

@iamwyza This issue can be closed since it has been implemented and now merged in #6421.

@volkanciloglu
Copy link

hi. I use the keypress event, but it just doesn't work when I press ctrl key. The disadvantage of using alphabetic and numeric keys.

@OrBin
Copy link
Contributor

OrBin commented Oct 19, 2019

hi. I use the keypress event, but it just doesn't work when I press ctrl key. The disadvantage of using alphabetic and numeric keys.

That's exactly why we enabled binding keyup and keydown events. Just use those events to trigger whatever you want on Ctrl press.

@volkanciloglu
Copy link

I do not need this. I want to turn Drawing mode on and off by pressing a key.

@OrBin
Copy link
Contributor

OrBin commented Oct 19, 2019

I see. It's not Leaflet that puts this limit - Ctrl key just doesn't trigger the keypress events on the browser, and that's why we enabled these events.
You can achieve your desire by binding keyup for Ctrl.

Schleuse pushed a commit to Schleuse/Leaflet that referenced this issue Dec 3, 2019
* Added support for 'keydown' and 'keyup' events, as requested in issue Leaflet#5734

* Added tests for 'keydown', 'keypress' and 'keyup' events binding and constified the key codes used in the test file
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

6 participants