Skip to content

Instantly share code, notes, and snippets.

@ypresto
Last active March 1, 2018 14:22
Show Gist options
  • Save ypresto/3db9e9a0150a02fe08e440b80b4bd421 to your computer and use it in GitHub Desktop.
Save ypresto/3db9e9a0150a02fe08e440b80b4bd421 to your computer and use it in GitHub Desktop.
英数キーとかかなキーとかを同時押しの時だけAltキーにするHammerspoonの設定
local pressedKeyTable = {}
-- TODO: Consider about consumed per keys is necessary or not.
local consumed = false
local keyCodeTable = {}
keyCodeTable[0x66] = true -- EISUU
keyCodeTable[0x68] = true -- KANA
eventtap = hs.eventtap.new({ hs.eventtap.event.types.keyDown, hs.eventtap.event.types.keyUp }, function(event)
local keyCode = event:getKeyCode()
if keyCodeTable[keyCode] == true then
if event:getType() == hs.eventtap.event.types.keyDown then
pressedKeyTable[keyCode] = true
return true
end
pressedKeyTable[keyCode] = false
local currentConsumed = consumed
consumed = false
if currentConsumed == true then
return true
end
-- TODO: Modifier
return true, {
hs.eventtap.event.newKeyEvent({}, keyCode, true),
hs.eventtap.event.newKeyEvent({}, keyCode, false)
}
end
local somePressed = false
for keyCode, pressed in pairs(pressedKeyTable) do
if pressed == true then
somePressed = true
break
end
end
if somePressed == true then
consumed = true
local flags = event:getFlags()
flags["alt"] = true
event:setFlags(flags)
end
end)
eventtap:start()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment