iOS Swift Interrupt Keyboard Events

时光总嘲笑我的痴心妄想 提交于 2019-12-03 16:21:15

I finally managed to get it working. Below is the code if anyone ever needs it.

var keys = [UIKeyCommand]()

override func viewDidLoad() {
    super.viewDidLoad()
    //configureGameControllers()

    for digit in "abcdefghijklmnopqrstuvwxyz"
    {
        keys.append(UIKeyCommand(input: String(digit), modifierFlags: nil, action:  Selector("keyPressed:")))
    }
}

override func canBecomeFirstResponder() -> Bool {
    return true
}

override var keyCommands: [AnyObject]? {
    get {
        return keys
    }
}


func keyPressed(command: UIKeyCommand) {
    println("user pressed \(command.input)")
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!