本文共 1302 字,大约阅读时间需要 4 分钟。
您可以使用Applescript自动鼠标单击.
tell application "System Events"
tell application process "Application_Name"
key code 53
delay 1
click (click at {1800, 1200})
end tell
end tell
如果要在浏览器窗口中单击,可以在Javascript的帮助下使用Applescript
tell application "safari"
activate
do JavaScript "document.getElementById('element').click();"
end tell
纯粹通过终端,您可以创建一个名为click.m或任何您喜欢的名称的文本文件,并使用以下代码进行保存
// File:
// click.m
//
// Compile with:
// gcc -o click click.m -framework ApplicationServices -framework Foundation
//
// Usage:
// ./click -x pixels -y pixels
// At the given coordinates it will click and release.
//
// From http://hints.macworld.com/article.php?story=2008051406323031
#import
#import
int main(int argc, char *argv[]) {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSUserDefaults *args = [NSUserDefaults standardUserDefaults];
int x = [args integerForKey:@"x"];
int y = [args integerForKey:@"y"];
CGPoint pt;
pt.x = x;
pt.y = y;
CGPostMouseEvent( pt, 1, 1, 1 );
CGPostMouseEvent( pt, 1, 1, 0 );
[pool release];
return 0;
}
然后按照说明编译它:
gcc -o click click.m -framework ApplicationServices -framework Foundation
并将其移动到相应的系统文件夹以方便使用
sudo mv click /usr/bin
sudo chmod +x /usr/bin/click
现在你可以运行一个简单的终端命令来操纵鼠标
click -x [coord] -y [coord]
注意:Jardel Weyrich提供了一个更全面的代码示例,here和John Dorian提供了一个用Java编写的出色解决方案,here
转载地址:https://blog.csdn.net/weixin_39626369/article/details/111457960 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!