Skip to content

Instantly share code, notes, and snippets.

@kimitoboku
Created April 8, 2019 14:08
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 kimitoboku/7660d9d5d78e3960a8ae4b2135781f68 to your computer and use it in GitHub Desktop.
Save kimitoboku/7660d9d5d78e3960a8ae4b2135781f68 to your computer and use it in GitHub Desktop.
local prevKeyCode
local leftCommand = 0x37
local rightCommand = 0x36
local eisuu = 0x66
local kana = 0x68
local alert_eikana
local function keyStroke(modifiers, character)
hs.eventtap.keyStroke(modifiers, character, 1000)
end
local function handleEvent(e)
local keyCode = e:getKeyCode()
local isCmdKeyUp = not(e:getFlags()['cmd']) and e:getType() == hs.eventtap.event.types.flagsChanged
if isCmdKeyUp and prevKeyCode == leftCommand then
keyStroke({}, eisuu)
hs.alert.closeSpecific(alert_eikana)
alert_eikana = hs.alert.show("ABC", 0.3)
elseif isCmdKeyUp and prevKeyCode == rightCommand then
keyStroke({}, kana)
hs.alert.closeSpecific(alert_eikana)
alert_eikana = hs.alert.show("Hiragana", {fillColor = {blue = 1, alpha = 0.75}}, 0.3)
end
prevKeyCode = keyCode
end
eventtap = hs.eventtap.new({hs.eventtap.event.types.flagsChanged, hs.eventtap.event.types.keyDown, hs.eventtap.event.types.keyUp}, handleEvent)
eventtap:start()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment