谁能举例说明如何创建一个模拟按return键的NSEvent?
发布于 2010-10-04 07:36:39
您应该了解一下NSEvent Class Reference,更具体地说,就是-keyEventWithType:location:modifierFlags:timestamp:windowNumber:context:characters:charactersIgnoringModifiers:isARepeat:keyCode:。
从那里开始,这应该不会很困难。构造所有必要的组件,并使用NSApplication的-sendEvent:方法发送事件。
发布于 2014-11-27 05:12:38
您可以使用此Swift-Code创建一个简单的键盘事件:
let ThePoint = CGPoint(x:0,y:0)
let theEventType: NSEventType = NSEventType(rawValue: 10)! // = KeyDown
let theModifierFlags: NSEventModifierFlags = NSEventModifierFlags(rawValue: 0)
var event = NSEvent.keyEventWithType(theEventType, location: ThePoint, modifierFlags: theModifierFlags, timestamp: 0.0, windowNumber: 0, context: nil, characters: "\n", charactersIgnoringModifiers: "", isARepeat: false, keyCode: 0)
NSApplication.sharedApplication().sendEvent(event!)https://stackoverflow.com/questions/3851878
复制相似问题