我一直在使用
swift中的
Cocoa OSX项目,需要使用键盘输入来执行操作.在keydown上我想在窗口上移动一个对象,但是一旦键松开就停止对象.我查看了AppKit的文档并找到了KeyDown函数,但我似乎无法弄清楚如何使用它.我想在我的游戏更新计时器中创建一个函数来调用它.谢谢
import Cocoa import Appkit @NSApplicationMain class AppDelegate: NSObject,NSApplicationDelegate { @IBOutlet weak var window: NSWindow! func applicationDidFinishLaunching(aNotification: NSNotification) { // Insert code here to initialize your application func keyDown(theEvent: NSEvent) { if (theEvent.keyCode == 1){ println("test") } } } func applicationWillTerminate(aNotification: NSNotification) { // Insert code here to tear down your application }
}
这是一些示例代码:
override func keyDown(theEvent: NSEvent) { if (theEvent.keyCode == 1){ //do whatever when the s key is pressed } }
关键代码:
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。