Skip to content

Instantly share code, notes, and snippets.

@codeocelot
Last active June 2, 2023 17:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codeocelot/fa3b1a6650b9d40fe8f367ac42b7e5de to your computer and use it in GitHub Desktop.
Save codeocelot/fa3b1a6650b9d40fe8f367ac42b7e5de to your computer and use it in GitHub Desktop.
Switch keyboard lang based on active application
-- Add the following to your init.lua (or create it if it doesn't exist)
local Keyboard = require "keyboard"
Keyboard:init()
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