Skip to content

Commit

Permalink
feat(hammerspoon): add umlauts to app mode
Browse files Browse the repository at this point in the history
Enables typing Swedish characters (å, ä, ö) using the App Mode modal.
Super hacky implementation. Switching keyboard layouts on press.
Introducing a short delay seems to be required.
  • Loading branch information
eliasnorrby committed Feb 26, 2021
1 parent 2f0e0d0 commit b7c2c04
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 4 deletions.
8 changes: 4 additions & 4 deletions keyboard/hammerspoon/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ require('modules.app-mode')
wifi = require('modules.wifi')

-- Reload Hammerspoon
appMode:bind({}, '[', function()
appMode:bind({}, ']', function()
hs.reload()
end)

-- Connect to wifi
appMode:bind({}, ']', function()
wifi.connect()
end)
-- appMode:bind({}, ']', function()
-- wifi.connect()
-- end)

hs.notify.new({title='Hammerspoon', informativeText='Ready to rock 🤓🤘'}):send()
45 changes: 45 additions & 0 deletions keyboard/hammerspoon/modules/app-mode/init.lua
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
-- A global variable for the App Mode
appMode = hs.hotkey.modal.new()
appModeStatusMessage = message.new('App Mode')
appModeBlocked = false

function enterAppMode()
if (appModeBlocked) then
return
end
appModeStatusMessage:show()
appMode:enter()
end
Expand Down Expand Up @@ -31,6 +35,47 @@ end
-- Bind the right cmd key
f16 = hs.hotkey.bind({}, 'F16', enterAppMode, exitAppMode)

-- Swedish bindings
-- 33 = [ = å
-- 41 = ; = ö
-- 39 = ' = ä
local keysToMirror = {
33,
41,
39
}

local modifiersToEnable = {
'',
'shift'
}

hs.fnutils.each(keysToMirror, function(k)
local swedishMap = "Swedish - Pro"
local usMap = "U.S."
local delay = 0.008
hs.fnutils.each(modifiersToEnable, function(m)
appMode:bind(m, k, function()
exitAppMode()
appModeBlocked = true

hs.timer.doAfter(0*delay, function()
hs.keycodes.setLayout(swedishMap)
end)

hs.timer.doAfter(1*delay, function()
keyUpDown(m, k)
appModeBlocked = false
end)

hs.timer.doAfter(2*delay, function()
hs.keycodes.setLayout(usMap)
enterAppMode()
end)
end)
end)
end)

-- Non-app bindings
-- vim movement:
local charactersToKeystrokes = {
Expand Down

0 comments on commit b7c2c04

Please sign in to comment.