Last active
June 2, 2023 17:16
-
-
Save codeocelot/fa3b1a6650b9d40fe8f367ac42b7e5de to your computer and use it in GitHub Desktop.
Switch keyboard lang based on active application
This file contains hidden or 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
-- Add the following to your init.lua (or create it if it doesn't exist) | |
local Keyboard = require "keyboard" | |
Keyboard:init() |
This file contains hidden or 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
function keyboardWatcher(name, event, app) | |
if event == hs.application.watcher.activated then | |
print('activated', name) | |
end | |
if name == 'KSP' or name == 'PrisonArchitect' or name == 'RimWorld by Ludeon Studios' or name == 'Cities: Skylines' or name == 'Paradox Launcher' then | |
if event == hs.application.watcher.activated then | |
hs.keycodes.setLayout("U.S.") | |
end | |
if event == hs.application.watcher.deactivated then | |
hs.keycodes.setLayout("Programmer Dvorak") | |
end | |
end | |
if name == 'KSP' then | |
if event == hs.application.watcher.activated then | |
hs.keycodes.setLayout("Dvorak") | |
end | |
if event == hs.application.watcher.deactivated then | |
hs.keycodes.setLayout("Programmer Dvorak") | |
end | |
end | |
if name == 'Timberborn' then | |
if event == hs.application.watcher.activated then | |
hs.keycodes.setLayout("U.S.") | |
end | |
if event == hs.application.watcher.deactivated then | |
hs.keycodes.setLayout("Programmer Dvorak") | |
end | |
end | |
end | |
Keyboard = {} | |
function Keyboard.init() | |
watcher = hs.application.watcher.new(keyboardWatcher) | |
watcher:start() | |
end | |
return Keyboard |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment