最近我一直在处理node.js模块NodObjC (非常酷的模块),我组装了一个简单的模块黄鼠狼,它使您能够通过node.js控制鼠标,现在我正在尝试通过CGWindowListCopyWindowInfo获取打开的窗口上的信息(想法是使用该信息和虚拟鼠标功能来做一些有趣的事情)。我对目标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的问题页上发布了这个问题)
发布于 2015-04-14 01:57:33
这已经在NodObjC版本1.0.1中得到了修正。
https://stackoverflow.com/questions/25595194
复制相似问题