gpt4 book ai didi

macos - Swift OSX 按键事件

转载 作者:IT王子 更新时间:2023-10-29 05:46:55 25 4
gpt4 key购买 nike

我一直在快速处理 Cocoa OSX 项目,该项目需要使用键盘输入来执行操作。在按下键时,我想在窗口中移动一个对象,但是一旦松开键就停止对象。我查看了 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
}

}

关键代码: enter image description here

关于macos - Swift OSX 按键事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28012566/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com