rMouse: rMouse: Automate mouse clicks and send keyboard input

Description Details Examples

Description

rMouse is inspired by packages like pyautogui in Python. The goal of the package is to let users create simple mouse and keyboard macros to automate user input. The rMouse package utilizes the Java Robot Class and depends on the rJava package. Make sure the R version corresponds to the Java version, e.g. 64-bit R with 64-bit Java. Troubleshooting rJava can be done via its documentation or online.

Details

rMouse creates a Java Robot Object (jRobot) and an Mouse Info Object (jMouseInformation) upon loading. The functions in the package are wrapper functions to call the methods of the Java objects. The functions can be divided in three categories: delays, mouse input and keyboard input. Delay functions are setAutoDelay(ms) and delay(ms), and work similar to Base R's Sys.sleep(time). The delay functions specify the time interval between commands where the system waits. move(x,y), left() and right() are mouse input functions to move the mouse cursor and send a left or a right click. With coord() and pos() it is possible to get the current position of the mouse cursor. record() is a work-around solution to record n mouse moves after a specified time interval has passed (e.g. every 5 seconds), as the Java Robot Class does not provide any methods to record mouse clicks. Moreover, it prints out an R code template to the console which can be used to rapidly build mouse macros. Finally, there are two functions to send keyboard input: type(string) allows to generate key presses for [0-9], [A-Z] and [a-z]. Spaces, periods and commas are allowed, however some special characters like "!" and "?" throw an error as the virtual key mapping in Java deviates from the generated raw bytes in R. specialKey(key) allows to send "ESC", "ENTER" or "TAB" key presses.

Each function has a build-in emergency stop procedure. If the mouse cursor is in the top left corner at pixel(x = 0, y = 0), then the execution is suspended. By setting the failSafe parameter of the function to FALSE, the emergency stop procedure is turned off.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
## Not run: 
setAutoDelay(ms)  # automatic delay in milliseconds
delay(1000)       # wait 1000 miliseconds

move(0,0)  # move to top left corner; pixel(0,0)
left()     # left click
right()    # right click
coord()    # return cursor coordinates as a list
pos()      # print cursor coordinates to console
record()   # record mouse moves and print template

type(string)     # type a string; no special characters
specialKey(key)  # send "ESC", "ENTER" or "TAB"

## End(Not run)

rMouse documentation built on May 1, 2019, 9:23 p.m.