JohannesKlauss / react-hotkeys-hook

React hook for using keyboard shortcuts in components.
https://react-hotkeys-hook.vercel.app/
MIT License
2.7k stars 114 forks source link

Press `g` then `h` combination #989

Open ThisIsJustUs opened 1 year ago

ThisIsJustUs commented 1 year ago

Is your feature request related to a problem? Please describe. No

Describe the solution you'd like Not sure if this already exists or not. I'm looking for a way to express a key sequence. In apps like Linear or Jira you can navigate using key combinations like g then h. Unfortunately, I didn't find a way yet to achieve the same using react-hotkeys-hook.

Describe alternatives you've considered The library react-hotkeys is able to do that using a string like 'g a'

JohannesKlauss commented 1 year ago

Hi @ThisIsJustUs Yes, this is something I would like to add. But this might have to wait a bit, since I think a clean up of the code logic has a bigger priority for now.

The-Podsiadly commented 1 year ago

Why not transition the event listenser to use Mousetrap for sequence?

alexgleason commented 1 year ago

Seems like it should be possible to work around this with useRecordHotkeys, or maybe by storing some state in the callback of useHotkeys.

The-Podsiadly commented 1 year ago

I figured out an adhoc way of doing this, but it's not fully tested. Works good enough for what I need.

Here's the gist for the two files I changed. I made changes within the L89-L181 to manage a state with a setTimeout. The validator now checks to see if the expected key is selected. I also included the modifier into the keys to properly going through the sequence. Otherwise a ctrl+/ does not work.

Kudos to jamiebuilds / tinykeys for the sequence traversing.

strafe commented 7 months ago

This would be a cool feature. I was looking to implement a Konami code easter egg since I'm already using this package.

pondorasti commented 5 months ago

Would love this feature too!