开发者

mouseclick script help

I need to get the mouse to clic开发者_如何学JAVAk on a spot on the screen, to be specific a flash object in safari.... Id tried to do this with applescript but it didnt work. Then I found this script on the internet.

    // 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;
}

I have only scripted in applescript so I didnt quite understood it

but when I activate it it clicks on the top left

but here is my question, what should I chance in the script to make it click other places than in the top corner

more info about the script on this website: http://hints.macworld.com/article.php?story=2008051406323031


This is stuff that you learn in most introductory programming courses. A complete answer would be very long, so I just tell you a few cornerstones:

  • The program that you downloaded is not a script
  • It's objective-C-sourcecode
  • You need to learn how to work with the Terminal application (the command line).
  • You need to learn how to invoke commands on the terminal (e.g. gcc)
  • You have to understand the meaning of the word compile. In this case it's something the author wanted you to do at the command line.

Second step:

  • // starts a comment in Objective C
  • gcc ... is the command that should be executed on the command line to compile the program
  • ./click is what you do to invoke the program (after you compiled it :-) )

gcc -o click click.m -framework ApplicationServices -framework Foundation means:

  • gcc: Gnu C Compiler
  • -o click: The program should be named click
  • click.m: This should be the name of the source code (the file that you called 'script')

hope this helps...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜