 |
 |
Reading Keyboard Events
|
 |
|
 |
|
Fresh-Faced Recruit
Join Date: Nov 2002
Status:
Offline
|
|
In my NSView subclass I want to be able to read events to the keyboard (up/down arrows espically). My first problem is getting the event to my subclass in the first place. I have -acceptsFirstResponder returning YES, but whenever i press a key when my app is lanuched, all I get is a beep. How do I channel keyboard events to my subclass and how do I exctract the key pressed from the event?
BTW, I'm trying to write pong by myself.
|
|
|
| |
|
|
|
 |
|
 |
|
Clinically Insane
Join Date: Oct 2001
Location: San Diego, CA, USA
Status:
Offline
|
|
Are you sure that the view is actually your first responder? Sometimes that connection isn't made properly, for whatever reason.
|
|
Chuck
___
"Instead of either 'multi-talented' or 'multitalented' use 'bisexual'."
|
| |
|
|
|
 |
|
 |
|
Fresh-Faced Recruit
Join Date: Nov 2002
Status:
Offline
|
|
As far as I know it is. What other ways are there to making the view first responder.
|
|
|
| |
|
|
|
 |
|
 |
|
Junior Member
Join Date: Oct 2001
Status:
Offline
|
|
you need to subclass the window the view is in...
|
|
I be that insane n***a from the psycho ward.
|
| |
|
|
|
 |
|
 |
|
Fresh-Faced Recruit
Join Date: Nov 2002
Status:
Offline
|
|
explaination? please? 
|
|
|
| |
|
|
|
 |
|
 |
|
Junior Member
Join Date: Oct 2001
Status:
Offline
|
|
...You need the overload the function:
Code:
- (BOOL)canBecomeKeyWindow
{
return YES;
}
as such.
|
|
I be that insane n***a from the psycho ward.
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Feb 2001
Location: Vancouver, WA
Status:
Offline
|
|
Um, only if the window can't become key for some reason (e.g. it's a utility panel). If it's just a normal window, you only need to make your view the first responder. There are many ways to do this, but if you want it to automatically be first responder when the window opens, the easy way to do that is to connect it to the window's initialFirstResponder outlet in IB.
|
|
|
| |
|
|
|
 |
|
 |
|
Fresh-Faced Recruit
Join Date: Apr 2001
Status:
Offline
|
|
In you view subclass, do you have the following methods returning YES?
- (BOOL)acceptsFirstResponder
- (BOOL)resignFirstResponder
- (BOOL)becomeFirstResponder
and have you implemented the (void)keyDonw  NSEvent *)event method?
Also, have in IB, have you connected the View to the initialFirstResponder outlet for the window? Oops, see Rickster's post just above.
(Last edited by lfrog2; May 7, 2003 at 08:50 AM.
)
|
|
|
| |
|
|
|
 |
|
 |
|
Fresh-Faced Recruit
Join Date: Nov 2002
Status:
Offline
|
|
I fixed it.
Grrrrr, -accept sFirstResponder NOT acceptFirstResponder. 
|
|
|
| |
|
|
|
 |
|
 |
|
Fresh-Faced Recruit
Join Date: Apr 2001
Status:
Offline
|
|
Originally posted by Spiffster:
I fixed it.
Grrrrr, -acceptsFirstResponder NOT acceptFirstResponder.
Looks like the type of problems I normally have 
|
|
|
| |
|
|
|
 |
|
 |
|
Dedicated MacNNer
Join Date: May 2001
Location: Edinburgh, UK
Status:
Offline
|
|
I'm also having problems with keyboard events in an NSView. What I'm doing is running a full screen NSMovie view that I've created in an NSWindow manually. Could someone explain to me how to do this or link me to example code that does this? Please explain it simply as my knowledge of Cocoa and Obj-C is still far from good. [I come from a C and Java background]
|
|
|
| |
|
|
|
 |
 |
|
 |
|
|
|
|
|

|
|
 |
Forum Rules
|
 |
 |
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
 |
 |
 |
 |
|
 |
|