Skip to content
/ robot Public

Clojure wrapper to simplify writing desktop scripts with java.awt Robot and Clipboard

License

Notifications You must be signed in to change notification settings

D00mch/robot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

30 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

robot

A Clojure library designed to simplify using java.awt for handling desktop manipulation commands.
For example, I use robot to change theme in apps:

Clojars Project

alt text

Launching apps

;; Open google.com in default browser
(r/launch-uri! "https://google.com")

;; Open default email app
(r/launch-uri! "mailto:arturdumchev@gmail.com")

Keyboard

(require '[robot.core :as r])

;; simulate pressing a single key 
(r/type! :shift)

;; simulate pressing hot keys
(r/hot-keys! [:cmd :space])

;; type whole text 
(r/type-text! "typing this letters")

Mouse

;; move cursor to position
(r/mouse-move! 280 1200)

;; getting mouse position
(r/mouse-pos) ;; => [280 1200]

;; simulate mouse click
(r/mouse-click!)

;; simulate mouse wheel
(r/scroll! 10)

Clipboard

;; put into clipboard
(r/clipboard-put! "text to put in clipboard")

;; get from clipboard
(r/clipboard-get-string) ;; => text that was in the clipboard

Delay

;; you can delay, which will use thread/sleep under the hood
(r/sleep 50)

;; you can also pass delays inside typing functions
(r/type! :k 50) ;; passing millis between press and release

;; the same with mouse
(r/mouse-click! 100) 

Pixel colors

(def x 280)
(def y 1200)
(def width 60)

;; get pixel color as argb integer
(pixel-argb-int x y)        ;=> -16777216 

(r/int->argb -16777216)     ;=> {:alpha 255, :red 0, :green 0, :blue 0}
(pixel-argb x y)            ;=> {:alpha 255, :red 0, :green 0, :blue 0} 

;; get pixel color as java.awt.Color 
(pixel-color x y)

;; get list of pixel corols as {:keys [alpha red green blue]}
(r/pixel-rgb-range-hor x y width r/int->argb)

(r/pixel-rgb-range x y 3 2) ;=> ((-11332 -11332 -11332) (-11332 -11332 -11332))

Java interop

(import java.awt.event.KeyEvent)

(r/type! KeyEvent/VK_A)

(r/hot-keys! [KeyEvent/VK_ALT KeyEvent/VK_SPACE])

Finding particular key

There is a function that returns a map with key-codes to key-names:

(r/get-my-keyboard)
;; =>
{3 "", 8 "", 9 "", 10 "", 12 "", 16 "", 17 "", 18 "" ... }

There is also a function to get the name of the particular key-code:

(r/get-key-name 61440)
;; => "F13"

Examples

  • Article about writing a clojure script to open docker and two terminal windows
  • Script to notify developer about standup in Slack
  • Script to change theme (vim, emacs, chrome, slack, osx, telegram)

License

Copyright © 2020 Artur Dumchev

This program and the accompanying materials are made available under the terms of the Eclipse Public License 2.0 which is available at http://www.eclipse.org/legal/epl-2.0.

This Source Code may also be made available under the following Secondary Licenses when the conditions for such availability set forth in the Eclipse Public License, v. 2.0 are satisfied: GNU General Public License as published by the Free Software Foundation, either version 2 of the License, or (at your option) any later version, with the GNU Classpath Exception which is available at https://www.gnu.org/software/classpath/license.html.

About

Clojure wrapper to simplify writing desktop scripts with java.awt Robot and Clipboard

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published