我需要让鼠标点击屏幕上的某个位置,特别是在safari中的flash对象.... 我试图用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
答案 0 :(得分:2)
这是你在大多数入门编程课程中学到的东西。一个完整的答案会很长,所以我只告诉你一些基石:
gcc
)compile
的含义。在这种情况下,作者希望您在命令行中执行此操作。第二步:
//
在Objective C gcc ...
是应该在命令行上执行以编译程序的命令./click
是您调用程序的方法(在编译之后:-)) gcc -o click click.m -framework ApplicationServices -framework Foundation
的意思是:
gcc
:Gnu C Compiler -o click
:该程序应命名为click
click.m
:这应该是源代码的名称(您称为'脚本'的文件)希望这会有所帮助...