• 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
Re: Cocoa, C++, Keyboard input and Timers
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Cocoa, C++, Keyboard input and Timers


  • Subject: Re: Cocoa, C++, Keyboard input and Timers
  • From: Andreas Monitzer <email@hidden>
  • Date: Tue, 17 Jun 2008 00:45:01 +0200

On Jun 16, 2008, at 23:47, Josh de Lioncourt wrote:

To that end, we're redeveloping many old titles, primarily in C++ for the bulk of the coding to make porting between Mac and Windows simpler. The games have no graphical interface to speak of, only an audio one.

First off, Cocoa programs have to be written in Objective C. However, when using the file extension .mm instead of .m, you can mix Objective C and C++ in the same file (you can't subclass across programming languages, though).


I need the app to be able to capture keyboard input when the application window has focus, take action based on that input, or, if the input is not valid to the game, let it pass through to the OS. My experience is mostly in Windows development, and I have no idea even where to start looking to accomplish this for the Mac OS X platform. Can you point me in the right direction?

Generally, you have to hook into the responder chain of the application somewhere and implement the following NSResponder methods:
- (void)keyDown:(NSEvent *)theEvent;
- (void)keyUp:(NSEvent *)theEvent;
- (void)flagsChanged:(NSEvent *)theEvent;


I can think of three options:
* Subclass NSApplication and declare it as the principal class for the application
* Subclass NSWindow and use that class for your single window
* Subclass NSControl (or maybe NSImageView), and pass an instance of it to -setContentView: of the window you're creating.


Next, I need to be able to keep track of real-time during the game. In Windows, we'd use something like GetTickCount to accomplish this. Is there an equivalent on the Mac side? Again, pointing me in the right direction would be tremendously appreciated.

[NSDate date] (for an NSDate object) or [NSDate timeIntervalSinceReferenceDate] (for a double value) should do the trick.


And, any other advice regarding development of C++ that can be ported and maintained easily between both OS's would be very welcome.

Try to keep the OS-specific parts in separate files and keep the interface between them to a minimum.


HTH

andy

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Cocoa, C++, Keyboard input and Timers
      • From: Josh de Lioncourt <email@hidden>
References: 
 >Cocoa, C++, Keyboard input and Timers (From: Josh de Lioncourt <email@hidden>)

  • Prev by Date: Re: Cocoa, C++, Keyboard input and Timers
  • Next by Date: Re: Cocoa, C++, Keyboard input and Timers
  • Previous by thread: Re: Cocoa, C++, Keyboard input and Timers
  • Next by thread: Re: Cocoa, C++, Keyboard input and Timers
  • Index(es):
    • Date
    • Thread