mirror of
https://github.com/nmasur/dotfiles
synced 2024-11-22 15:45:38 +00:00
isolate escape from control key
This commit is contained in:
parent
269e7a1225
commit
4348c52b1f
@ -27,18 +27,40 @@ function obj:init()
|
|||||||
self.controlTap = hs.eventtap.new({hs.eventtap.event.types.flagsChanged},
|
self.controlTap = hs.eventtap.new({hs.eventtap.event.types.flagsChanged},
|
||||||
function(event)
|
function(event)
|
||||||
local newModifiers = event:getFlags()
|
local newModifiers = event:getFlags()
|
||||||
if not self.lastModifiers['ctrl'] then
|
|
||||||
if newModifiers['ctrl'] then
|
-- If this change to the modifier keys does not invole a *change* to the
|
||||||
if (newModifiers['shift'] and newModifiers['cmd']) then
|
-- 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
|
||||||
elseif newModifiers['shift'] then
|
-- any action.
|
||||||
hs.eventtap.keyStroke({'shift'}, 'escape', 0)
|
if self.lastModifiers['ctrl'] == newModifiers['ctrl'] then
|
||||||
else
|
return false
|
||||||
hs.eventtap.keyStroke(newModifiers, 'escape', 0)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
self.lastModifiers = newModifiers
|
|
||||||
|
-- Control was not down but is now
|
||||||
|
if not self.lastModifiers['ctrl'] then
|
||||||
|
self.lastModifiers = newModifiers
|
||||||
|
if (not self.lastModifiers['cmd'] and not self.lastModifiers['alt']) then
|
||||||
|
self.sendEscape = true
|
||||||
|
end
|
||||||
|
-- Control was down and is up
|
||||||
|
elseif (self.sendEscape == true and not newModifiers['ctrl']) then
|
||||||
|
self.lastModifiers = newModifiers
|
||||||
|
if newModifiers['shift'] then
|
||||||
|
hs.eventtap.keyStroke({'shift'}, 'escape', 0)
|
||||||
|
else
|
||||||
|
hs.eventtap.keyStroke(newModifiers, 'escape', 0)
|
||||||
|
end
|
||||||
|
self.sendEscape = false
|
||||||
|
else
|
||||||
|
self.lastModifiers = newModifiers
|
||||||
|
end
|
||||||
|
end
|
||||||
|
)
|
||||||
|
|
||||||
|
-- If any other key is pressed, don't send escape
|
||||||
|
self.asModifier = hs.eventtap.new({hs.eventtap.event.types.keyDown},
|
||||||
|
function(event)
|
||||||
|
self.sendEscape = false
|
||||||
end
|
end
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
@ -48,6 +70,7 @@ end
|
|||||||
--- Start sending `escape` when `control` is pressed and released in isolation
|
--- Start sending `escape` when `control` is pressed and released in isolation
|
||||||
function obj:start()
|
function obj:start()
|
||||||
self.controlTap:start()
|
self.controlTap:start()
|
||||||
|
self.asModifier:start()
|
||||||
end
|
end
|
||||||
|
|
||||||
--- ControlEscape:stop()
|
--- ControlEscape:stop()
|
||||||
@ -56,6 +79,7 @@ end
|
|||||||
function obj:stop()
|
function obj:stop()
|
||||||
-- Stop monitoring keystrokes
|
-- Stop monitoring keystrokes
|
||||||
self.controlTap:stop()
|
self.controlTap:stop()
|
||||||
|
self.asModifier:stop()
|
||||||
|
|
||||||
-- Reset state
|
-- Reset state
|
||||||
self.sendEscape = false
|
self.sendEscape = false
|
||||||
|
Loading…
Reference in New Issue
Block a user