Created
March 7, 2023 14:44
-
-
Save apelliciari/812664779c0a58a8a948ac1d27703a50 to your computer and use it in GitHub Desktop.
scriptino corso sicurezza hammerspoon
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
enableAutoClick = false | |
-- Seconds to delay before next click. 0.001 works OK. | |
speedDelay = 30 | |
targetMousePos = nil | |
function clickAndReturn() | |
local oldMousePos = hs.mouse.absolutePosition() | |
mouseLeftClick(targetMousePos) | |
mouseLeftClick(targetMousePos) | |
mouseLeftClick(oldMousePos) | |
end | |
function mouseRightClick() | |
-- Run right mouseclick | |
print("Right mouse click") | |
hs.eventtap.rightClick(hs.mouse.absolutePosition()) | |
end | |
function mouseLeftClick(pos) | |
-- Run left mouseclick | |
print("Left mouse click") | |
print(targetMousePos) | |
hs.eventtap.leftClick(pos) | |
end | |
function isAutoClickerEnabled() | |
return enableAutoClick | |
end | |
function setupClicker() | |
-- Set continuous run to true | |
enableAutoClick = true | |
print("Enabled autoclicker") | |
hs.timer.doWhile(isAutoClickerEnabled, clickAndReturn, speedDelay) | |
end | |
function stopClicker() | |
-- Stop autoclicker | |
print("Disable Autoclicker") | |
enableAutoClick = false | |
end | |
function sleep(n) | |
local t = os.clock() | |
while os.clock() - t <= n do | |
-- nothing | |
end | |
end | |
function registerTarget() | |
print("Target acquired") | |
targetMousePos = hs.mouse.absolutePosition() | |
end | |
-- hs.hotkey.bind({"cmd","alt","shift"}, "A", setupClicker) | |
-- hs.hotkey.bind({"cmd","alt","shift"}, "D", stopClicker) | |
hs.hotkey.bind({"cmd","shift"}, "7", setupClicker) | |
hs.hotkey.bind({"cmd","shift"}, "8", stopClicker) | |
hs.hotkey.bind({"cmd","shift"}, "9", registerTarget) | |
hs.hotkey.bind({"cmd","shift"}, "0", clickAndReturn) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment