[英]Moving the cursor in Mac OS X (in Python and/or R)
有人可以帮我弄清楚如何使用Python或R脚本在Mac OS X中移动光标吗? 计划是读取实时信号,并根据流的值向上或向下移动光标。 感谢您的帮助...谢谢!
好吧,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)
另外,如果有人要执行键盘事件,这就是这样做的方式。 以下是键入数字的代码:
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()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.