Add hammerspoon. Almost usable now...
This commit is contained in:
70
wm/hammerspoon/ctrlDoubleTap.lua
Executable file
70
wm/hammerspoon/ctrlDoubleTap.lua
Executable file
@@ -0,0 +1,70 @@
|
||||
local timer = require("hs.timer")
|
||||
local eventtap = require("hs.eventtap")
|
||||
|
||||
local events = eventtap.event.types
|
||||
|
||||
local module = {}
|
||||
|
||||
module.timeFrame = 1
|
||||
|
||||
module.action = function()
|
||||
hs.alert("You double tapped ctrl!")
|
||||
end
|
||||
|
||||
local timeFirstControl = 0
|
||||
local firstDown = false
|
||||
local secondDown = false
|
||||
|
||||
local noFlags = function(ev)
|
||||
local result = true
|
||||
for k,v in pairs(ev:getFlags()) do
|
||||
if v then
|
||||
result = false
|
||||
break
|
||||
end
|
||||
end
|
||||
return result
|
||||
end
|
||||
|
||||
local onlyCtrl = function(ev)
|
||||
local result = ev:getFlags().ctrl
|
||||
for k,v in pairs(ev:getFlags()) do
|
||||
if k ~= "ctrl" and v then
|
||||
result = false
|
||||
break
|
||||
end
|
||||
end
|
||||
return result
|
||||
end
|
||||
|
||||
local reset = function()
|
||||
timeFirstControl = 0
|
||||
firstDown = false
|
||||
secondDown = false
|
||||
end
|
||||
|
||||
module.eventWatcher = eventtap.new({events.flagsChanged, events.keyDown}, function(ev)
|
||||
if(timer.secondsSinceEpoch() - timeFirstControl) > module.timeFrame then
|
||||
reset()
|
||||
end
|
||||
|
||||
if ev:getType() == events.flagsChanged then
|
||||
if noFlags(ev) and firstDown and secondDown then
|
||||
if module.action then module.action() end
|
||||
reset()
|
||||
elseif onlyCtrl(ev) and not firstDown then
|
||||
firstDown = true
|
||||
timeFirstControl = timer.secondsSinceEpoch()
|
||||
elseif onlyCtrl(ev) and firstDown then
|
||||
secondDown = true
|
||||
elseif not noFlags(ev) then
|
||||
reset()
|
||||
end
|
||||
else
|
||||
reset()
|
||||
end
|
||||
return false
|
||||
end):start()
|
||||
|
||||
return module
|
||||
|
||||
Reference in New Issue
Block a user