Skip to content

Instantly share code, notes, and snippets.

@johndevedu
Last active June 11, 2019 15:45
Show Gist options
  • Save johndevedu/54e93fa47c08f9835dfbbcdcd3b5311c to your computer and use it in GitHub Desktop.
Save johndevedu/54e93fa47c08f9835dfbbcdcd3b5311c to your computer and use it in GitHub Desktop.
hammerspoon settings for Marble Trackball
function dump(o)
if type(o) == 'table' then
local s = '{ '
for k,v in pairs(o) do
if type(k) ~= 'number' then k = '"'..k..'"' end
s = s .. '['..k..'] = ' .. dump(v) .. ','
end
return s .. '} '
else
return tostring(o)
end
end
local inspect = require('inspect')
print(dump(hs.application.runningApplications()))
hs.hotkey.bind({"cmd", "alt", "ctrl"}, "R", function()
hs.reload()
end)
hs.hotkey.bind({"cmd", "alt", "ctrl"}, "Z", function()
local username = os.date('jlee-%b%d-%H%M@gmail.com')
hs.eventtap.keyStrokes(username);
hs.pasteboard.setContents(username);
end)
hs.hotkey.bind({"cmd", "alt", "ctrl"}, "X", function()
hs.eventtap.keyStrokes('Conference1!')
end)
env = require "env"
hs.hotkey.bind({"cmd", "alt", "ctrl"}, "V", function()
hs.eventtap.keyStrokes(env.open)
end)
hs.hotkey.bind({"cmd", "alt", "ctrl"}, "M", function()
hs.eventtap.keyStrokes('d0bf2bcc9af7ef6fe6bb2a4d543292f1')
end)
hs.hotkey.bind({"cmd", "alt", "ctrl"}, "N", function()
hs.eventtap.keyStrokes('SVOoQJaeX0eLboUOU0wSoQtt')
end)
hs.hotkey.bind({"cmd", "alt", "ctrl"}, "pad1", function()
hs.application.launchOrFocus("Google Chrome")
end)
hs.hotkey.bind({"cmd", "alt", "ctrl"}, "pad2", function()
hs.application.launchOrFocus("Visual Studio Code")
end)
hs.hotkey.bind({"cmd", "alt", "ctrl"}, "pad3", function()
hs.application.launchOrFocus("iTerm")
end)
hs.alert.show("Config loaded")
-- HANDLE SCROLLING WITH MOUSE BUTTON PRESSED
local scrollMouseButton = 3
local deferred = false
overrideOtherMouseDown = hs.eventtap.new({ hs.eventtap.event.types.otherMouseDown }, function(e)
local pressedMouseButton = e:getProperty(hs.eventtap.event.properties['mouseEventButtonNumber'])
if scrollMouseButton == pressedMouseButton
then
deferred = true
return true
end
end)
overrideOtherMouseUp = hs.eventtap.new({ hs.eventtap.event.types.otherMouseUp }, function(e)
local pressedMouseButton = e:getProperty(hs.eventtap.event.properties['mouseEventButtonNumber'])
if scrollMouseButton == pressedMouseButton
then
if (deferred)
then
overrideOtherMouseDown:stop()
overrideOtherMouseUp:stop()
overrideOtherMouseDown:start()
overrideOtherMouseUp:start()
return true
end
return false
end
return false
end)
local oldmousepos = {}
local scrollmult = -.75 -- negative multiplier makes mouse work like traditional scrollwheel
dragOtherToScroll = hs.eventtap.new({ hs.eventtap.event.types.otherMouseDragged }, function(e)
local pressedMouseButton = e:getProperty(hs.eventtap.event.properties['mouseEventButtonNumber'])
if scrollMouseButton == pressedMouseButton
then
-- print("scroll");
deferred = false
oldmousepos = hs.mouse.getAbsolutePosition()
local dx = e:getProperty(hs.eventtap.event.properties['mouseEventDeltaX'])
local dy = e:getProperty(hs.eventtap.event.properties['mouseEventDeltaY'])
local dxfinal = 0
local dyfinal = dy * math.abs(dy) * scrollmult
local scroll = hs.eventtap.event.newScrollEvent({dxfinal, dyfinal},{},'pixel')
-- put the mouse back
hs.mouse.setAbsolutePosition(oldmousepos)
return true, {scroll}
else
return false, {}
end
end)
-- keyDown:start()
overrideOtherMouseDown:start()
overrideOtherMouseUp:start()
dragOtherToScroll:start()
@johndevedu
Copy link
Author

init with middle click working, but on mousedown instead of mouseup

@johndevedu
Copy link
Author

Cleaned up and added additional keyboard bindings.

@johndevedu
Copy link
Author

added application bindings

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment