是否可以从 R 控制台控制鼠标指针?
我有这样的想法:
move_mouse(x_pos=100,y_pos=200) # move the mouse pointer to position (100,200)
mouse_left_button_down # simulate a press of the left button
move_mouse(x_pos=120,y_pos=250) # move mouse to select something
mouse_release_left_button # release the pressed button
在 MATLAB 中,可以使用以下代码进行类似的操作
import java.awt.Robot;
mouse = Robot;
mouse.mouseMove(0, 0);
mouse.mouseMove(100, 200);
我尝试将上述内容直接转换为如下所示的 R:
install.packages("rJava") # install package
library(rJava) # load package
.jinit() # this starts the JVM
jRobot <- .jnew("java/awt/Robot") # Create object of the Robot class
一旦我在 R 中获得了 jRobot,我尝试使用下面的两个命令调用它的方法“MouseMove(100,200)”,这两个命令都导致了错误。
jRobot$mouseMove(10,10)
Error in .jcall("RJavaTools", "Ljava/lang/Object;", "invokeMethod", cl, :
java.lang.NoSuchMethodException: No suitable method for the given parameters
或者
.jcall(jRobot,, "mouseMove",10,10)
Error in .jcall(jRobot, , "mouseMove", 10, 10) :
method mouseMove with signature (DD)V not found