Keyboard and Mouse Input Simulation for Windows OS

Control your keyboard and mouse with R code by simulating key presses and mouse clicks. The input simulation is implemented with the Windows API.

CRAN_Status_Badge CRAN_Status_Badge

KeyboardSimulator is a package for R language that make users simulate keyboard event, cursor movement and mouse click with simple R function.

This package provide 6 functions which are developed in C++:

  • Simulate keyboard key presses. Multiple keys can be pressed simultaneously by using + as separator.
  • keybd.release() Simulate the release of keyboard keys held by
  • Simulate left and right button of mouse clicks.
  • mouse.release() Simulate the release of mouse button held by
  • mouse.get_cursor() Get current cursor coordinate of screen.
  • mouse.move() Move cursor to specific coordinate of screen.

The supported keys are listed in keyboard_value.


Does KeyboardSimulator support operating systems other than Windows?

No, KeyboardSimulator is built on top of the Windows API and is not compatible with other operating systems.

This package doesn't work on my computer! How can I make it work?

Open a GitHub issue and let us know what version of Windows you are using and what keyboard and mouse hardware you have connected.

Package Setup



if (!require("devtools")) install.packages("devtools")


Simulate keyboard event

  • Press single key"Enter")
  • Press multiple keys with + as seperator"Alt+f4")
  • Hold keys with argument hold=TRUE and use keybd.release to release the held key"Alt", hold = TRUE)'Tab')

Simulate mouse event

  • Get current location of cursor
# Return the x,y coordinate of screen
[1] 960 540
  • Press mouse button"right")
  • Move cursor to the center of screen on 1080FHD monitor
mouse.move(960, 540)
  • Move cursor to the center of screen on 1080FHD monitor within 3 seconds
mouse.move(960, 540, duration=3)
  • Drag an item to center of screen = "left", hold = TRUE)
mouse.move(960, 540)



It is highly recommended that you use the RStudio IDE to develop this package. In addition to an R installation, you'll also need to install Rtools and a TeX distribution. TeX Live is a comprehensive distribution that seems to work well.

Once you have cloned this repository, you'll need to download the build package dependencies. These dependencies are managed with packrat and can be restored by running

if (!require(packrat)) install.packages("packrat")


The roxygen2 R package is used to manage KeyboardSimulator's documentation. Do not edit any of the files that have a warning comment at the top about manually editing those files!

You can regenerate package documentation with the RStudio shortcut Ctrl+Shift+Enter, or by running


The project is set up to do this whenever building and testing the package.



KeyboardSimulator 2.1.0

  • Add argument duration and step_ratio in mouse.move function

KeyboardSimulator 2.0.1

  • Update file

KeyboardSimulator 2.0

  • New mouse related function to simulator cursor movement and get cursor coordinate

KeyboardSimulator 1.1

  • Implement keyboard scan codes so simulated inputs can be detected by DirectInput applications

KeyboardSimulator 1.0

  • Initial release

Reference manual

It appears you don't have a PDF plugin for this browser. You can click here to download the reference manual.


2.6.0 by Jim Chen, a year ago

Report a bug at

Browse source code at

Authors: Jim Chen [aut, cre] , Jeff Keller [aut, ctb] , Garry Hopwood [ctb] , Chieh Hsu [ctb]

Documentation:   PDF Manual  

GPL (>= 2) | file LICENSE license

Imports Rcpp

Linking to Rcpp

See at CRAN