GithubHelp home page GithubHelp logo

Comments (3)

JohannesKlauss avatar JohannesKlauss commented on July 19, 2024

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.

psychedelicious avatar psychedelicious commented on July 19, 2024

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.

JohannesKlauss avatar JohannesKlauss commented on July 19, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.