This file contains 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
#!/usr/bin/env boot | |
(import 'java.awt.MouseInfo | |
'java.awt.event.KeyEvent | |
'java.awt.event.InputEvent) | |
(defn mouse-location [] | |
((juxt :x :y) (bean (.getLocation (MouseInfo/getPointerInfo))))) | |
(defn +- [& xs] | |
(let [[op] (shuffle [+ -])] | |
(apply op xs))) | |
(defn near [[x y] & {:keys [dist]}] | |
[(+- x (rand-int dist)) (+- y (rand-int dist))]) | |
(defn string->keycodes [s] | |
(mapv | |
(comp | |
#(KeyEvent/getExtendedKeyCodeForChar %) | |
#(Character/getNumericValue %)) | |
s)) | |
(defn -main [& args] | |
(let [bot (doto (java.awt.Robot.) | |
(.setAutoDelay 10))] | |
(while true | |
(.waitForIdle bot) | |
(let [[x y] (mouse-location) | |
[newx newy] (near [x y] :dist 200)] | |
(.mouseMove bot newx newy) | |
; Dangerous to uncomment! | |
;(.mousePress bot InputEvent/BUTTON1_DOWN_MASK) | |
;(.mouseRelease bot InputEvent/BUTTON1_DOWN_MASK) | |
(.mouseMove bot x y))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment