xcode - 鼠标单击脚本帮助

标签 xcode cocoa macos mouse

我需要让鼠标点击屏幕上的某个点,具体来说是 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

最佳答案

这是您在大多数入门编程类(class)中学到的内容。完整的答案会很长,所以我只告诉你一些基石:

  • 您下载的程序不是脚本
  • 这是 Objective-C 源代码
  • 您需要了解如何使用终端应用程序(命令行)。
  • 您需要学习如何在终端上调用命令(例如gcc)
  • 您必须理解编译这个词的含义。在本例中,这是作者希望您在命令行中执行的操作。

第二步:

  • // 在 Objective C 中开始注释
  • gcc ... 是编译程序时应在命令行上执行的命令
  • ./click 是您调用程序的方法(编译后:-) )

gcc -o click click.m -framework ApplicationServices -framework Foundation 意思是:

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

希望这有帮助...

关于xcode - 鼠标单击脚本帮助,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6317340/

相关文章:

ios - UILabel 从具有动态类型的静态 UITableViewCell 中消失

cocoa - 如何从外部命令行调用 cocoa 应用程序?

objective-c - 如何在我的项目中创建第二个目标来为 iOS 创建一个预填充的数据库

java - 苹果系统。无法识别 OpenJDK

macos - 获取 NSStatusItem 的长度

swift - 选择行时 UITableViewCell 不更新 UISwitch

iOS 和 Cocos2d : my app REALLY slow on simulator but is FINE on device

iphone - 仍然无法让CoreBluetooth在简单的名称发现应用程序中工作

cocoa - 将焦点设置在 NSMenu 中的 NSTextField 上?

python - 在 python 脚本中调用 bash 函数