• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Swift Keyboard Keypress input function needed.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Swift Keyboard Keypress input function needed.


  • Subject: Swift Keyboard Keypress input function needed.
  • From: Mutlu Qwerty <email@hidden>
  • Date: Mon, 09 Mar 2015 13:54:56 -0400
  • Importance: Normal

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@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: Swift Keyboard Keypress input function needed.
      • From: Jens Alfke <email@hidden>
  • Prev by Date: 64-bit int not being aligned in 32-bit ARM, causing crash
  • Next by Date: Re: Swift Keyboard Keypress input function needed.
  • Previous by thread: Re: 64-bit int not being aligned in 32-bit ARM, causing crash
  • Next by thread: Re: Swift Keyboard Keypress input function needed.
  • Index(es):
    • Date
    • Thread