2010-10-03 53 views

回答

0

你应该看看NSEvent Class Reference,更具体地说,-keyEventWithType:location:modifierFlags:timestamp:windowNumber:context:characters:charactersIgnoringModifiers:isARepeat:keyCode:

从那里,它应该不难。构建所有必要的组件,并使用NSApplication-sendEvent:方法发送事件。

+0

可以显示一个例子吗? – objectiveccoder001 2010-10-04 19:55:51

+0

你不应该真的需要一个例子(它很容易写,因为它是),但这里有一个看看:http://pastie.org/1199967。它假定你可以/应该改变你自己的很多信息。这取决于你使用的按键是什么,以及你想要达到的目标。 – 2010-10-05 03:32:15

1

您可以使用此斯威夫特代码创建一个简单的键盘 - 事件:

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!)