Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#!/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