Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Reading Keyboard Events

Reading Keyboard Events
Thread Tools
Fresh-Faced Recruit
Join Date: Nov 2002
Status: Offline
Reply With Quote
May 5, 2003, 08:17 PM
 
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
Reply With Quote
May 5, 2003, 09:04 PM
 
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
Reply With Quote
May 6, 2003, 02:15 PM
 
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
Reply With Quote
May 6, 2003, 03:25 PM
 
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
Reply With Quote
May 6, 2003, 07:30 PM
 
explaination? please?
     
Junior Member
Join Date: Oct 2001
Status: Offline
Reply With Quote
May 6, 2003, 09:28 PM
 
...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
Reply With Quote
May 7, 2003, 12:53 AM
 
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.
Rick Roe
icons.cx | weblog
     
Fresh-Faced Recruit
Join Date: Apr 2001
Status: Offline
Reply With Quote
May 7, 2003, 08:24 AM
 
In you view subclass, do you have the following methods returning YES?

- (BOOL)acceptsFirstResponder
- (BOOL)resignFirstResponder
- (BOOL)becomeFirstResponder

and have you implemented the (void)keyDonwNSEvent *)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
Reply With Quote
May 7, 2003, 05:58 PM
 
I fixed it.

Grrrrr, -acceptsFirstResponder NOT acceptFirstResponder.
     
Fresh-Faced Recruit
Join Date: Apr 2001
Status: Offline
Reply With Quote
May 8, 2003, 10:57 AM
 
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
Reply With Quote
May 12, 2003, 10:42 AM
 
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]
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 03:29 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2