Liking cljdoc? Tell your friends :D

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

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)

;; get pixel color at position
(pixel-color 280 1200)

Clipboard

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

;; get from clipboard
(r/clipboard-get-string) ;; => text to put in 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

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

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

Script to notify developer about standup in Slack
Script to change theme (vim, emacs, chrome, slack, osx, telegram)

License

Copyright © 2020 FIXME

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.

Can you improve this documentation? These fine people already did:
18385139, liverm0r & Artur Dumchev
Edit on GitHub

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close