Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Simulate keyboard press with Rstudio

Tags:

r

Looking for help with simulating keyboard press with Rstudio. My idea is to set my code to sys.sleep for some time and in meanwhile turn on the specific game (for example fifa or similar) and using Rstudio to simulate keyboard keys.

Want to train CNN / Q-learning process to manage to play a specific game in a mini situation.

Till now, checked this option in stack Overflow, but seems it's not working anymore.

One of the ideas, I had, is to use Rcpp package to implement C/C++ code in R. Founded one example how to simulate in C++, but so far I didn't manage to implement this code in Rcpp environment.

Any help would be really appreciated.

EDITED

My solution so far is to source Python code (tutorial in youtube):

from pynput.keyboard import Key, Controller

keyboard = Controller()

keyboard.press(Key.left) 
keyboard.release(Key.left)

Save the code as "code.py", then on RStudio install "reticulate" package and source code in RStudio by:

system("python code.py")

Keys can be founded in youtube video (attached above).

Good day.

p.s. Working on Windows 10

like image 635
Zygimantas Avatar asked Nov 01 '25 04:11

Zygimantas


1 Answers

There is a brand new R package KeyboardSimulator which is documented at

https://cran.r-project.org/web/packages/KeyboardSimulator/index.html

like image 165
2 revs, 2 users 67%Jim Chen Avatar answered Nov 03 '25 19:11

2 revs, 2 users 67%Jim Chen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!