Created
May 23, 2022 20:58
-
-
Save stepango/858507b16d74f729b14f8fad5c3482d7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Layout Switch | |
ctrlPressed = false | |
keyPressed = false | |
eventTypes = hs.eventtap.event.types | |
events = { eventTypes.flagsChanged, eventTypes.keyUp } | |
function indexOf(table, value) | |
local index = -1 | |
for i = 1, #table do | |
if value == table[i] then | |
return index | |
end | |
end | |
end | |
layouts = hs.keycodes.layouts() | |
layout = hs.keycodes.currentLayout() | |
current_index = indexOf(layouts, layout) | |
right_command_key = 0x36 | |
layoutWatcher = hs.eventtap.new(events, function(e) | |
local flags = e:getFlags() | |
local keyCode = e:getKeyCode() | |
if flags.cmd and keyCode == right_command_key and not (flags.alt or flags.shift or flags.ctrl or flags.fn) then | |
ctrlPressed = true | |
keyPressed = false | |
elseif ctrlPressed and not (flags.cmd or flags.alt or flags.shift or flags.ctrl or flags.fn) and not keyPressed then | |
ctrlPressed = false | |
if keyCode == right_command_key then | |
current_index = (current_index % #layouts) + 1 | |
hs.keycodes.setLayout(layouts[current_index]) | |
end | |
else | |
keyPressed = true | |
end | |
end) | |
layoutWatcher:start() | |
-- Periodic Things | |
hs.timer.doAt("00:00", "1h", function() | |
hs.application.launchOrFocus("Things3") | |
end):start() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment