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

tab as modifier? #1252

Closed
karkraeg opened this issue Mar 11, 2017 · 8 comments
Closed

tab as modifier? #1252

karkraeg opened this issue Mar 11, 2017 · 8 comments

Comments

@karkraeg
Copy link

karkraeg commented Mar 11, 2017

Hi! Is it possible to use the tab key as a modifier in combination with other keys and as tab key when pressed alone? Right now, when I use something like hs.hotkey.bind(tab, 's', function() hs.application.launchOrFocus("Safari") end) I can launch or focus Safari by pressing tab and s but I still press tab everytime…

@karkraeg
Copy link
Author

Not relevant

@jhegedus42
Copy link

i would like to know how to do this as well.... any hints ?

@karkraeg
Copy link
Author

Hi @jhegedus42 I did not pursue this, I was trying to recreate the Karabiner Applauncher Mode with Hammerspoon in 10.12 but since I didn’t find anything I let go of the idea. If you should be successfull keep me posted 😉

@jhegedus42
Copy link

myModifierMode = hs.hotkey.modal.new()

myModifierMode:bind({}, 'b', 
  function()
    myModifierMode.triggered = true
    -- do something
    hs.notify.new({title="Hammerspoon", informativeText="Hello World"}):send()
  end
)
	
myModifier = hs.hotkey.bind({}, "tab",
  function()
    myModifierMode:enter()
    myModifierMode.triggered = false
  end,
  function()
    myModifierMode:exit()
    if not myModifierMode.triggered then
      myModifier:disable()
      hs.eventtap.keyStroke({}, "tab")
      myModifier:enable()
    end
  end
)	

seems to work ...

@karkraeg
Copy link
Author

Wow, thanks! Works nice to launch Apps. However, if they are already running I now can switch to them but it’ll press tab once nonetheless. Anyhow, great to be able to use tab as a modifier now!

@knu
Copy link
Contributor

knu commented Mar 30, 2017

You probably need to change myModifier:enable() to something like hs.timer.doAfter(0.1, function() myModifier:enable() end) because the key stroke generated above is sent after the enclosing function exits.

@jhegedus42
Copy link

jhegedus42 commented Mar 31, 2017

this is an example for more bindings (with repeating key functionality):
(took me a while to get this right)

this way you can implement home row keys, diamond navigation, whatever....

replacement for karabiners keyoverlaid modifier


myModifierMode = hs.hotkey.modal.new()

function binder(from,to,mods)
	local function f ()
	    myModifierMode.triggered = true
	    hs.eventtap.keyStroke(mods, to, 1000) 
  	end
	myModifierMode:bind({}, from, f,nil,f )
end
	
myModifier = hs.hotkey.bind({}, "tab",
  function()
    myModifierMode:enter()
    myModifierMode.triggered = false
  end,
  function()
    myModifierMode:exit()
    if not myModifierMode.triggered then
      myModifier:disable()
      hs.eventtap.keyStroke({}, "tab")
      myModifier:enable()
    end
  end
)		
			

binder('b','c')																																									
binder('e','t')		

@jhegedus42
Copy link

for two modifier keys this was the best i could do:


 function builder(mmm,key,var)
	 var = hs.hotkey.bind({}, key,
	  function()
	    mmm:enter()
	    mmm.triggered = false
	  end,
	  function()
	    mmm:exit()
	    if not mmm.triggered then
	      var:disable()
	      hs.eventtap.keyStroke({}, key)
	      var	:enable()
	    end
	  end
	)
end


		

function binder(from,to,mods,mmm)
	local function f ()
	    mmm.triggered = true
	    hs.eventtap.keyStroke(mods, to, 1000) 
  	end
	mmm:bind({}, from, f,nil,f )
end
								
mmtab = hs.hotkey.modal.new()
mm1=builder(mmtab,"tab")

mmz = hs.hotkey.modal.new()
mm2=builder(mmz,"z")

binder('b','c',nil,mmtab)																																									
binder('e','t',nil, mmtab)																																															
		
binder('b','c',nil,mmz)																																									
binder('e','t',nil, mmz)	

teddywing added a commit to teddywing/dothammerspoon that referenced this issue Jun 19, 2019
Since I overrode the F1 through F4 keys globally, there was no way to
access press a non-custom variant of these keys. Realised this when
trying to access the manual in Mutt, which is bound to F1.

Add Shift-F1–F4 bindings that map to F1–F4, in case we need access to
the original set of keys.

Needed to add a `doAfter` delay after disabling the binding because the
delay seems to take a bit to go through. Thanks to 'knu'
(https://github.com/knu) for the tip:
Hammerspoon/hammerspoon#1252 (comment)

Also gleaned it from:
https://stackoverflow.com/questions/40986242/key-repeats-are-delayed-in-my-hammerspoon-script
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants