Assuming your are using this in conjunction of one of the answers I gave you back in mid November regarding Calculator, then the modified Lua code below works for me to switch to the previous application when pressing the enter key while in Calculator.
Example Lua code:
-- Create a hotkey used to trap the enter key and disable it.
-- It will then be enabled/disabled as Calculator is focused/unfocused
-- When enabled and the enter key is pressed it presses = then command C.
applicationCalculatorEnterHotkey = hs.hotkey.bind({}, "return", function()
-- Press the '=' key to finish the calculation.
hs.eventtap.keyStroke({}, "=")
-- Copy the result to the clipboard.
hs.eventtap.keyStroke({"cmd"}, "C")
-- Bring up the App Switcher.
hs.eventtap.keyStroke({"cmd"}, "tab")
-- Act on the selected App in the App Switcher.
-- This works in testing with Calculator, however
-- may not work in other applications.
hs.eventtap.keyStroke({}, "=")
end)
applicationCalculatorEnterHotkey:disable()
Notes:
我添加了两个hs.eventtap.keyStroke
到原来的code与评论。
执行中hs.eventtap.keyStroke({"cmd"}, "tab")
in the Console 锤勺会自动切换到上一个应用不显示应用程序切换器,但是当用于applicationCalculatorEnterHotkey
function它显示了应用程序切换器 as if ⌘-Tab已被按下并且⌘ key没有被释放。这可能是一个错误,不确定,因为没有对该问题进行足够的测试/研究,因为明显的解决方案是以编程方式按enter key,但是这不能从内部完成applicationCalculatorEnterHotkey
function因为它已经困住了enter key in 计算器.
然而,在这个特定的用例中,这就是hs.eventtap.keyStroke({}, "=")
用于表现好像enter key被再次按下并且是独一无二的计算器.