Hello, can someone provide the Swift function that inputs a keyboard keypress?
I need the digits, 1 thru 9, and the arrow cursors as input to my Sudoku game.
Ive tried NSNotifications and NSResponder:here is some code:
import Cocoa
import Foundation
import AppKit
class ViewController: NSViewController {
override func viewDidLoad() {
super.viewDidLoad()
let myNSResponder = myResponder()
if NSApp.resignFirstResponder() {
if myNSResponder.acceptsFirstResponder {
println("Were accepting First Responder")
}else {
println("Not accepting First Responder")
}
}else {
println("NSApp Will Not Resign")
}
}
override var representedObject: AnyObject? {
didSet {
// Update the view, if already loaded.
}
}
}
class myResponder: NSResponder {
override func keyDown(theEvent: NSEvent) {
println("Key down ")
println(theEvent.description)
}
override func becomeFirstResponder() -> Bool {
return true
}
}// end of Class myResponder
Running program prints "Not accepting First Responder" and keypresses inputs
are ignored giving me a system beep.Thomas
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list ([email protected])
Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/xcode-users/archive%40mail-archive.com
This email sent to [email protected]