我最近一直在搞乱 node.js 模块NodObjC(非常酷的模块 btw),我把一个简单的模块macmouse放在一起,它使您能够通过 node.js 控制鼠标,现在我正在尝试通过获取打开窗口上CGWindowListCopyWindowInfo
的信息(想法是使用该信息和虚拟鼠标功能做一些有趣的事情)。我对 Objective C 没有太多经验,但我在一篇博文中偶然发现了一个例子:
http://b2cloud.com.au/tutorial/monitoring-any-window-in-os-x/
我在 Xcode 中测试了它,
#import "Foundation/Foundation.h"
#import "Cocoa/Cocoa.h"
NSArray* windows = CFBridgingRelease(CGWindowListCopyWindowInfo(kCGWindowListOptionAll, kCGNullWindowID));
NSLog(@"%@", windows);
它会打印出我想要的所有数据以及更多数据,但现在我被困在如何使用 NodObjC 模块来做到这一点。
这是我的尝试(使用 NodObjC v1.0.0):
var $ = require('NodObjC');
$.framework('Foundation');
$.framework('Cocoa');
var pool = $.NSAutoreleasePool('alloc')('init');
var windowList = $.CFBridgingRelease($.CGWindowListCopyWindowInfo($.kCGWindowListOptionAll, $.kCGNullWindowID));
console.log(windowList);
pool('drain');
但我收到以下错误:
/Users/loknar/Desktop/nodobjc_stuff/node_modules/ffi/lib/_foreign_function.js:55
throw e
^
TypeError: error setting argument 0 - writePointer: Buffer instance expected as third argument
at Object.writePointer (/Users/loknar/Desktop/nodobjc_stuff/node_modules/ffi/node_modules/ref/lib/ref.js:740:11)
at Object.set (/Users/loknar/Desktop/nodobjc_stuff/node_modules/ffi/node_modules/ref/lib/ref.js:482:13)
at Object.alloc (/Users/loknar/Desktop/nodobjc_stuff/node_modules/ffi/node_modules/ref/lib/ref.js:514:13)
at ForeignFunction.proxy (/Users/loknar/Desktop/node_robot/nodobjc_stuff/ffi/lib/_foreign_function.js:50:22)
at Function.unwrapper (/Users/loknar/Desktop/nodobjc_stuff/node_modules/NodObjC/lib/core.js:297:31)
at Object.<anonymous> (/Users/loknar/Desktop/nodobjc_stuff/listOfWindows.js:44:20)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
这里出了什么问题?(我也在NodObjC 的问题页面上发布了这个问题)