2010-11-20 57 views

回答

1

嘿。 我有这个相同的问题,我不确定这是你想要的,但它可以让你将鼠标移动到屏幕上给定的坐标并执行一次点击。你需要英特尔,但我没有,所以我无法使用它,但我会给你任何你可能需要的帮助。链接:http://hints.macworld.com/article.php?story=2008051406323031

23

您可以使用Applescript自动点击鼠标。

tell application "System Events" 
    tell application process "Application_Name" 
     key code 53 
     delay 1 
     click (click at {1800, 1200}) 
    end tell 
end tell 

如果你想在浏览器窗口中单击您可以使用AppleScript的使用Javascript

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 <Foundation/Foundation.h> 
#import <ApplicationServices/ApplicationServices.h> 

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

+2

+1优秀的答案!工作很好。 – 2014-11-01 08:21:43

+0

你是一个巫师吗? – paulwal222 2015-06-14 17:04:59