Comments (3)
Yes, this is currently "by design". The hook listens to every keystroke and saves all currently held keys. If another key is pressed it looks at all held down keys and triggers each callback that matches. Otherwise combinations like a+s
are not possible.
But, I agree that this is somewhat counter intuitive. Maybe it makes sense to only check for held down keys on combinations where it is necessary, something like a+s
, because other combos like space
or meta+s
don't need that. All information is present in the event.
Thanks for raising this.
from react-hotkeys-hook.
Thanks for the explanation. I should explain a bit more why this is a problem with a real-world example.
Our project has some modal hotkeys and this behaviour interferes.
For example, while shift
is held, interactions with numbers use finer steps than normal. If you are dragging an object around, it normally snaps to a grid, but while you hold shift it doesn't snap.
While space
is held, the move tool is temporarily activated (it's a different tool normally).
A common use pattern is to activate the move tool with space
, move an object around a bit, then also hold shift
to get finer control of it.
Unfortunately this doesn't work with the current behaviour, because the hook reports a space
keyup/down when you keyup/down on shift
, causing the tool to change when it shouldn't. I couldn't figure out how to derive the actual state of the space
key when this occurs other than to store additional state outside the callback.
I suppose I could use e.g. isHotkeyPressed
within the keydown callback to double-check that space
is held down, but that feels like a lot of fanagling. There's also the second arg to the callback but it seems to not have accurate information in it.
from react-hotkeys-hook.
Yes I agree. This hook wasn't intended to be used in such complicated scenarios, haha, but I'll gladly improve it to get to work for this example. But it is not that simple to implement and would be a breaking change. So this needs to go into version 5.
from react-hotkeys-hook.
Related Issues (20)
- slash, backslash, and bracketright are not defined correctly in parseHotkeys.ts HOT 9
- [BUG] meta on Mac does not capture cmd like the docs say HOT 3
- What is v4.5.0? HOT 1
- [BUG] Working locally, but not in production HOT 6
- [BUG]The keyboard combination doesn't work in focused input HOT 2
- [PSA] You probably want `equal` instead of `+` (plus/bracketright) HOT 1
- The useRecordHotkeys hook should allow us to programatically set the keys HOT 1
- [BUG] Does not handle the 'Alt Graph' modifier key HOT 1
- Match a key pressed by character (optionally maybe) instead of keyCode HOT 1
- [BUG] Hotkeys stuck on `contextmenu` event. HOT 1
- Several entries in mappedKeys look suspicious HOT 2
- [BUG] preventDefault seems not work when use `command + s ` HOT 2
- [BUG] Why is # key mapped to Backslash HOT 1
- [BUG] Callback called on each matched key in array HOT 3
- [BUG] hotKeys trigger from input inside WebComponent HOT 2
- [BUG] isHotkeyPressed requires ALL buttons to be pressed, not just at least one
- [BUG] v5.0.0-1, "useKey" option also seems to (partially) activate "ignoreModifiers" HOT 3
- [BUG] don't trigger hot keys when input focus HOT 1
- [BUG] `mod` modifier listens to `ctrl` on macOS HOT 5
- [BUG] document property of options param in useHotkeys method not working
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from react-hotkeys-hook.