evantravers / Hyper.spoon

20 stars 2 forks source link

Creating a shortcut with modifier only #7

Closed wongjustin98 closed 1 year ago

wongjustin98 commented 1 year ago

What's a good way to accomplish showing shortcut hints on holding down a modifier?

Example: I currently have CMD+z/x/c/v mapped to various things using Hyper.

However, I often forget what the keys are, or what they do. I would like holding down CMD to show some text.

Tried doing this:

Hyper:bind({}, nil, function() 
  hs.alert("shortcut list like z, h, k, l, m, etc.")
end)

and also an empty string.

evantravers commented 1 year ago

Hmm… what an interesting problem.

So technically Hyper is a spoon, but it's an overloaded hs.hotkey.modal, and therefore has a couple callbacks you could use.

I just tested this:

function spoon.Hyper:entered()
  -- do whatever display you want

  return self
end

You could use hs.alert to make a display… you may even be able to update the display for different hotkeys. Check out hs.inspect(spoon.Hyper.keys), you may be able to generate a table magically from what you've already bound.

I kinda feel like @megalithic showed me a Hyper-key implementation that had this built in. If we wanted to build on onto Hyper we could add an argument for an optional "description" and display those on keypress. Feel free to submit a pull-request if you build something neat!

wongjustin98 commented 1 year ago

Awesome that's exactly what I needed!

Looks great with the alert. I'll hack on this to try and tie into generating that table and create a PR if something generic comes out of it.

Thank you!