PDA

View Full Version : [Resolved] Can't get key presses?




ArtOfWarfare
Jul 16, 2012, 12:00 AM
I'm trying to make my first 3D game ever.

An issue I'm having is receiving key press events. I've added keyDown: to all of my classes, and I've set them to do an NSLog when they get an event, (except TSOgreView, because that's cpp only,) but I never get an event (instead the computer just makes an error sound when I hit a key.)

Suggestions?

I can't figure out who is the first responder... or even which the first responder should be.

Here's what my class layout looks like so far:

TSAppDelegate - all it does right now is start up a TSController
TSController - first, it creates a TSOgreView.
TSOgreView - starts up the Ogre3D engine and creates a window to add its view to.

TSController then takes the window, adds itself as the delegate, gets its contentView, and adds a TSCocoaView (for receiving touch events) that perfectly fills in the contentView.

TSController then makes a TSHUDController, which starts itself up with TSHUD.xib, a panel with a transparent background and a few views on it that provide the 2D overlay for my game. TSController adjusts the panel to perfectly overlap with the game's main window.

Edit:

A classic case of simply writing and posting the necessary details to receive help making the answer apparent...

All I did was make it so the main window (the one created by the TSOgreView and handed to the TSController,) makes the TSCocoaView its first responder. The TSCocoaView now properly logs that a key was pressed. Here's my next few issues:

1 - How do I determine what key was pressed?
2 - How do I pass along key presses that I don't want it to receive?

Odds are I'll figure out both within a few minutes of googling...

2X Edit:

And indeed, it seems I have... my answers were:

1 - Get the event's characters (with [event characters] ); it's an NSString containing all of the keys that were pressed, it seems. Check if the desired key is in the set.
2 - Just use [super keyDown:event]; - The default implementation is to just pass it along, thus by using super, you end up passing it along.

I'm now out of questions on this topic, I guess I'll just mark it resolved.