1

有人可以帮我弄清楚如何使用 Python 或 R 脚本在 Mac OS X 中移动光标吗?该计划是读取实时信号并根据流式值向上或向下移动光标。感谢您的帮助...谢谢!

4

2 回答 2

6

好吧,R 允许您使用 C,所以它闻起来像作弊,但有效:

library(inline)
move.cursor <- cfunction(c(x="numeric",y="numeric"),
  "CGWarpMouseCursorPosition(CGPointMake(asReal(x),asReal(y)));
   return R_NilValue;",
  "#include <ApplicationServices/ApplicationServices.h>",,"C",
  libargs="-framework AppKit")

然后只需调用以下命令即可移动光标move.cursor

move.cursor(100, 100)
于 2012-08-27T01:23:52.887 回答
0

此外,如果有人想做键盘事件,这就是它的完成方式。以下是输入数字的代码:

which.key <- 1
eval(parse(text = paste("c.key <- 'CGEventRef e = CGEventCreateKeyboardEvent(NULL, (CGKeyCode)", which.key+17, ", true); CGEventPost(kCGSessionEventTap, e); CFRelease(e); return R_NilValue;'", sep = "")))

KeyPress <- cfunction(
    body = c.key,
    includes = "#include <ApplicationServices/ApplicationServices.h>",
    language = "C",
    libargs = "-framework AppKit")

KeyPress()
于 2012-09-06T04:55:59.517 回答