View Full Version : Ecape key to pause game task
BobbyWatson
2002.06.03, 01:00 PM
Hi everyone
I'm currently working on the escape key to pause the game task and I've had a bit of a problem. I tried searching Apple's documentation, cocoa mailing lists and cocoa headers, but I didn't find anything.
Here's the question : is there a constant (something like kNSEscapeCharCode) which represents the escape key? In my searches, I came across some sort of key dictionnary in the System/Library folder, but I don't think I found anything that would be helpful...
Thanks!
:confused:BobbyWatson
Kjurtyl
2002.06.03, 03:34 PM
NSEvent has a bunch of constants for keys like the arrows and the function keys. As far as I can tell, there isn't a constant for the escape key (although there is for just about every other key). You can explore NSEvent to be sure however.
I would suggest looking into the keyCode method of NSEvent. You should be able to figure out a way of getting the escape key's numerical value and use that.
-Kjurtyl.
aleph0
2002.06.03, 06:31 PM
#27
BobbyWatson
2002.06.03, 09:23 PM
I worked a bit on the escape key using the "27" given by Aleph0, and it actually works! It compiles and pauses when you press the escape key! I still have a small buck to solve though. Shouldn't be too long, I'll probably commit it to the CVS tomorrow.
BobbyWatson
Pazolli
2002.06.03, 10:10 PM
Great to hear, I look forward to seeing your contribution. Thanks Aleph0 for the information.
Mark.
BobbyWatson
2002.06.03, 11:29 PM
It's finished, I just commited the changes to the CVS. Enjoy!
Here's a summary of the changes :
-added an enum in the globals.h file for the escape key (kEscapeKey = 27)
-modified the -keyDown method in GameView so it can respond to kEscapeKey keydown events.
I'm not entirely proud of that "27" thing, I'm pretty sure there must be a better way to do it...
BobbyWatson
Kjurtyl
2002.06.04, 07:19 PM
I haven't had a chance to check your changes yet (no access), but I'm curious as to why your not happy with the "27" thing. More precisely, I'd like to know what you meant by that.
Every key on the keyboard has a number associated to it, which is how we can access them. I can imagine that there should be a constant for the escape key, but essentially, that's still just a number. I might be misinterpreting your unease however, which is why I'd like some clarifications on it.
-Kjurtyl.
BobbyWatson
2002.06.04, 08:16 PM
Originally posted by Kjurtyl
I can imagine that there should be a constant for the escape key, but essentially, that's still just a number.
That's pretty much it. I think I read somewhere in Apple's documentation that this number was hardware dependent. In other words, will it also work on a Chinese keyboard? Though it works on a French Canadian keyboard (mine) and it apparently works on a US keyboard, so maybe I'm wrong with that hardware dependant thing.
BobbyWatson
Pazolli
2002.06.04, 08:50 PM
Generally they would aim to have key code compatibility, it's not worth worrying about.
Mark.
AndyWanKenobi
2002.06.04, 09:55 PM
I just saw this and I'll say that I dealt with this same thing when I was setting enter and return or exit the story screen.
Maybe we should add several of these keys to the enum in Globals.h for use in the program.
Does anyone else concur?
Pazolli
2002.06.05, 01:51 AM
I don't think that's a bad idea, but it's not essential.
Mark
vBulletin® v3.6.8, Copyright ©2000-2008, Jelsoft Enterprises Ltd.