mirror of
https://github.com/nmasur/dotfiles
synced 2024-11-10 05:12:56 +00:00
add trackpad movement threshold
This commit is contained in:
parent
b4536a7dcc
commit
f135378d65
@ -19,6 +19,7 @@ obj.homepage = 'https://github.com/jasonrudolph/ControlEscape.spoon'
|
|||||||
obj.license = 'MIT - https://opensource.org/licenses/MIT'
|
obj.license = 'MIT - https://opensource.org/licenses/MIT'
|
||||||
|
|
||||||
function obj:init()
|
function obj:init()
|
||||||
|
self.movements = 0
|
||||||
self.sendEscape = false
|
self.sendEscape = false
|
||||||
self.lastModifiers = {}
|
self.lastModifiers = {}
|
||||||
|
|
||||||
@ -28,7 +29,7 @@ function obj:init()
|
|||||||
function(event)
|
function(event)
|
||||||
local newModifiers = event:getFlags()
|
local newModifiers = event:getFlags()
|
||||||
|
|
||||||
-- If this change to the modifier keys does not invole a *change* to the
|
-- If this change to the modifier keys does not involve a *change* to the
|
||||||
-- up/down state of the `control` key (i.e., it was up before and it's
|
-- up/down state of the `control` key (i.e., it was up before and it's
|
||||||
-- still up, or it was down before and it's still down), then don't take
|
-- still up, or it was down before and it's still down), then don't take
|
||||||
-- any action.
|
-- any action.
|
||||||
@ -41,16 +42,20 @@ function obj:init()
|
|||||||
self.lastModifiers = newModifiers
|
self.lastModifiers = newModifiers
|
||||||
if (not self.lastModifiers['cmd'] and not self.lastModifiers['alt']) then
|
if (not self.lastModifiers['cmd'] and not self.lastModifiers['alt']) then
|
||||||
self.sendEscape = true
|
self.sendEscape = true
|
||||||
|
self.movements = 0
|
||||||
end
|
end
|
||||||
-- Control was down and is up
|
-- Control was down and is up, hasn't been blocked by another key, and
|
||||||
elseif (self.sendEscape == true and not newModifiers['ctrl']) then
|
-- isn't above the movement threshold
|
||||||
|
elseif (self.sendEscape == true and not newModifiers['ctrl'] and self.movements < 12) then
|
||||||
self.lastModifiers = newModifiers
|
self.lastModifiers = newModifiers
|
||||||
|
-- Allow for shift-escape
|
||||||
if newModifiers['shift'] then
|
if newModifiers['shift'] then
|
||||||
hs.eventtap.keyStroke({'shift'}, 'escape', 0)
|
hs.eventtap.keyStroke({'shift'}, 'escape', 0)
|
||||||
else
|
else
|
||||||
hs.eventtap.keyStroke(newModifiers, 'escape', 0)
|
hs.eventtap.keyStroke(newModifiers, 'escape', 0)
|
||||||
end
|
end
|
||||||
self.sendEscape = false
|
self.sendEscape = false
|
||||||
|
self.movements = 0
|
||||||
else
|
else
|
||||||
self.lastModifiers = newModifiers
|
self.lastModifiers = newModifiers
|
||||||
end
|
end
|
||||||
@ -64,14 +69,15 @@ function obj:init()
|
|||||||
end
|
end
|
||||||
)
|
)
|
||||||
|
|
||||||
-- If mouse is moving, don't send escape
|
-- If mouse is moving significantly, don't send escape
|
||||||
self.scrolling = hs.eventtap.new({hs.eventtap.event.types.gesture},
|
self.scrolling = hs.eventtap.new({hs.eventtap.event.types.gesture},
|
||||||
function(event)
|
function(event)
|
||||||
local touches = event:getTouches()
|
local touches = event:getTouches()
|
||||||
local i, v = next(touches, nil)
|
local i, v = next(touches, nil)
|
||||||
while i do
|
while i do
|
||||||
if v["phase"] == "moved" then
|
if v["phase"] == "moved" then
|
||||||
self.sendEscape = false
|
-- Increment the movement counter
|
||||||
|
self.movements = self.movements + 1
|
||||||
end
|
end
|
||||||
i, v = next(touches, i) -- get next index
|
i, v = next(touches, i) -- get next index
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user