2011-06-11 69 views
0

我需要获得鼠标点击屏幕上的一个点,以具体的Safari浏览器中的闪存对象.... Id试图用applescript做到这一点,但它没有奏效。然后我在互联网上找到了这个脚本。鼠标点击脚本帮助

// 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. 


    #import <Foundation/Foundation.h> 
    #import <ApplicationServices/ApplicationServices.h> 


    int main(int argc, char *argv[]) { 
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; 
    NSUserDefaults *args = [NSUserDefaults standardUserDefaults]; 


    // grabs command line arguments -x and -y 
    // 
    int x = [args integerForKey:@"x"]; 
    int y = [args integerForKey:@"y"]; 


    // The data structure CGPoint represents a point in a two-dimensional 
    // coordinate system. Here, X and Y distance from upper left, in pixels. 
    // 
    CGPoint pt; 
    pt.x = x; 
    pt.y = y; 


    // This is where the magic happens. See CGRemoteOperation.h for details. 
    // 
    // CGPostMouseEvent(CGPoint  mouseCursorPosition, 
    //     boolean_t  updateMouseCursorPosition, 
    //     CGButtonCount buttonCount, 
    //     boolean_t  mouseButtonDown, ...) 
    // 
    // So, we feed coordinates to CGPostMouseEvent, put the mouse there, 
// then click and release. 
// 
CGPostMouseEvent(pt, 1, 1, 1); 
CGPostMouseEvent(pt, 1, 1, 0); 


[pool release]; 
return 0; 
} 

我只在AppleScript的脚本化所以我不很明白它

但是当我激活它点击左上角

但这里是我的问题,我应该在机会脚本,使其单击其他地方比在右上角

关于本网站上的脚本的详细信息:http://hints.macworld.com/article.php?story=2008051406323031

回答

2

这是你在大多数介绍性编程课程中学到的东西。一个完整的答案会是很长,所以我只是告诉你几个基石:

  • ,已下载的程序是没有剧本的
  • 这是客观-C-源代码
  • 你需要学习如何使用终端应用程序(命令行)。
  • 您需要了解如何调用终端上的命令(例如gcc
  • 您必须了解单词compile的含义。在这种情况下,作者希望您在命令行上执行此操作。

第二步:

  • //开始在目标C
  • gcc ...评论是,应该在命令行上执行编译程序
  • ./click的命令是你做什么调用程序(编译之后:-))

gcc -o click click.m -framework ApplicationServices -framework Foundation种 手段:

  • gcc:GNU C编译器
  • -o click:程序应该被命名为click
  • click.m:这应该是源代码(你称为 '脚本' 的文件)的名称

希望这有助于...

+0

感谢迈克尔,但我可以弄清楚如何与终端,然后isentĴ ust一个地方,你可以放置你可以放置鼠标位置的x和y坐标....它在哪里?????? – applescripthelpme 2011-06-11 19:12:05

+0

这是该计划的一个参数。你说'./click -x 200 -y 300',它会被点击定位(200,300) – Michael 2011-06-11 19:15:58

+1

。只需阅读源代码,就可以解释所有细节! – Michael 2011-06-11 19:17:23