No, really. What is the proper way to handle keyboard input in a game using Cocoa?

前端 未结 2 2138
醉酒成梦
醉酒成梦 2021-02-07 07:29

Let\'s say you\'re creating a game for Mac OS X. In fact, let\'s say you\'re creating Quake, only it\'s 2011 and you\'d prefer to only use modern, non-deprecated frameworks.

相关标签:
2条回答
  • 2021-02-07 07:47

    This looks promising:

    +[ NSEvent addLocalMonitorForEventsMatchingMask:handler: ]

    Seems to be new in 10.6 and sounds just like what you're looking for. More here:

    http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/ApplicationKit/Classes/NSEvent_Class/Reference/Reference.html%23//apple_ref/occ/clm/NSEvent/addLocalMonitorForEventsMatchingMask:handler:

    0 讨论(0)
  • 2021-02-07 08:00

    As others have said, there’s nothing wrong with using -flagsChanged:. There is another option: use the IOKit HID API. You should be using this anyway for joystick/gamepad input, and arguably mouse input; it may or may not be convenient for keyboard input too, depending on what you’re doing.

    0 讨论(0)
提交回复
热议问题