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 > Keys.

Keys.
Thread Tools
Admin Emeritus
Join Date: Oct 2000
Location: Boston, MA
Status: Offline
Reply With Quote
Jan 25, 2001, 10:26 AM
 
Cocoa question(s):

I have a button. How can I make it so when I press a key, that button is activated?

How can I capture key events in general?
"Against stupidity, the gods themselves contend in vain" (Schiller)
     
Mac Enthusiast
Join Date: Feb 2000
Location: Storrs,Connecticut, USA
Status: Offline
Reply With Quote
Jan 25, 2001, 11:09 AM
 
Get info on it in interface builder and there is a field wich say something like key. Below it is also a popup menu with stuuf like retun and tab in it so you don't have to remember that tab is \t. Just put the key in the key field in Interface Editor.

Capturing keyboard events, for a game or something is kind of hard. I never really looked into how to do that . If all that you want to do is make buttons respond to keystrokes then just use Interface Builder.
     
Admin Emeritus
Join Date: Oct 2000
Location: Boston, MA
Status: Offline
Reply With Quote
Jan 25, 2001, 05:16 PM
 
I tried that key thing a while ago, but I couldn't get it to work. Is there any place which has code for a game in Cocoa, or something that gets into more detail with the event loop than the standard runtime?
"Against stupidity, the gods themselves contend in vain" (Schiller)
     
Dedicated MacNNer
Join Date: Jun 2000
Location: Dundas, Ontario, Canada
Status: Offline
Reply With Quote
Jan 31, 2001, 10:01 AM
 
I have never actually done this but I will be trying soon and if I have any luck I will post the example and send you a link but I am pretty sure that you can create an object of type NSEvent and use that to find out what is going on. It has a "keyDownEvent" or something that tells you when someone is pressing a key and you can then use that same object, I think, to get the code of the key that was pressed. Just search the apple documentation for "NSEvent" and you should get something. I seem to recall them having some decent documentation for this Class.

Hope that helps,
Jeff.
Spectral Class
"Shedding Light on Innovation"
     
Admin Emeritus
Join Date: Oct 2000
Location: Boston, MA
Status: Offline
Reply With Quote
Jan 31, 2001, 10:28 AM
 
Someone answered this in another thread.

Basically, you can subclass NSWindow or NSApplication and have it capture events by overriding keyDown NSEvent *)aEvent

Overriding event handling in NSApplication is pretty powerful.
"Against stupidity, the gods themselves contend in vain" (Schiller)
     
   
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 12:11 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