diff --git a/src/cljck/io.clj b/src/cljck/io.clj index 60b9bf5..3ef56a6 100644 --- a/src/cljck/io.clj +++ b/src/cljck/io.clj @@ -1,6 +1,7 @@ (ns cljck.io (:gen-class) (:require + [cljck.utils :refer [multi-functions]] [cljck.io [keyboard :refer [press]] [mouse :refer [click move-to mouse-pointer scroll-down scroll-up]]] @@ -20,58 +21,68 @@ The argument is expected to be a vector like [:move-to 100 100] or [:click]. Dispatches on first." - first) - -(defmethod process-event :click + (comp name first)) + +(defmethod process-event :default + [exp] + (throw (IllegalArgumentException. + (with-out-str + (println "The following expression wasn't recognized:") + (clojure.pprint/pprint exp) + (println "No such command:" (first exp)) + (println "Valid commands:" (multi-functions process-event)) + (println "Check the API in the README for help."))))) + +(defmethod process-event "click" [_] (click :left)) -(defmethod process-event :if +(defmethod process-event "if" [[_ condition then else]] (if (process-event condition) (process-event then) (process-event else))) -(defmethod process-event :move-to +(defmethod process-event "move-to" [[_ x y]] (move-to x y)) -(defmethod process-event :pointer-near +(defmethod process-event "pointer-near" [[_ x y distance]] (let [[mouse-x mouse-y] (mouse-pointer)] (and (< (- x distance) mouse-x (+ x distance)) (< (- y distance) mouse-y (+ y distance))))) -(defmethod process-event :press +(defmethod process-event "press" [[_ key-string]] (press key-string)) -(defmethod process-event :repeat +(defmethod process-event "repeat" [[_ n & commands]] (dotimes [_ n] (doseq [command commands] (process-event command)))) -(defmethod process-event :repeatedly +(defmethod process-event "repeatedly" [[_ & commands]] (loop [] (doseq [command commands] (process-event command)) (recur))) -(defmethod process-event :scroll-down +(defmethod process-event "scroll-down" [[_ & amount]] (apply scroll-down amount)) -(defmethod process-event :scroll-up +(defmethod process-event "scroll-up" [[_ & amount]] (apply scroll-up amount)) -(defmethod process-event :wait +(defmethod process-event "wait" [[_ miliseconds]] (> multimethod + (.getMethodTable) + (map first) + (remove (partial = :default)) + (sort)))