-4

Is there a way to disable the keyboard in macos x?

I am looking for a way I can use this functinality in an application. So preferably something that can be done programatically and does not need root previlages?

I want the keyboard to be dsabled everywhere in the os, even if the application is in the background, until I enable it by pushing a butten for example.

I am new to mac os programming so will appreciate more elaborations :)

UPDATE: I am trying to use this: CGEventTapCreate but cannot get it to work. Anyone nows how to make it work in swift 3?

armin
  • 35
  • 1
  • 4

1 Answers1

0

You can override the keyDown and keyUp events and leave the function without calling its super class

override func keyDown(with event: NSEvent) {
    //super.keyDown(event)
}
override func keyUp(with event: NSEvent) {
    //super.keyUp(event)
}

The above code works for NSTextView

For NSTextField, you should manually delete the letter entered. As for NSTextfield's keyDown event will not be called when overrided.

override func keyUp(with event: NSEvent) {
    self.stringValue = ""
}

I used these techniques, but not really sure if this is right way to do... But it works :P

mouseymaniac
  • 259
  • 2
  • 9
  • Thank for the responce, but let make myself clear. I want to completely disabe the keyboard, any input, anywhere, not just in the app. – armin Nov 20 '18 at 18:42
  • This would not work. I want to disable/enable keyboard based on clickong a button. Thanks though. – armin Nov 25 '18 at 18:54