Good Folk,
I have some behavior that puzzles me a great deal about how arrow keys
are handled. I would appreciate any sort of advice or insight.
I am on a Mac, a PPC iBook, 10.4.6 of the OS, using Xcode 2.2, with
SDL 1.2.10, and the extras package.
The smallest possible expression of my puzzling behavior was to add a
couple of lines to one of the sample applications for Xcode, in
TemplatesForXcode/SDL Application, I added to the main.c there the
following code in the event loop:
case SDL_KEYDOWN:
printf ( "keydown: %x %d\n", event.key.keysym.unicode,
event.key.keysym.sym ); break;
case SDL_KEYUP:
printf ( “keyup: %x %d\n”, event.key.keysym.unicode,
event.key.keysym.sym ); break;
This sample application normally starts up, and waits for any
key-press to quit. This addition should report, for every key down
and key up what the unicode and sym values are.
If I start this modified app, and then press on keyboard of my laptop
the left arrow, then the up, then right, then down, I get the
following output:
keydown: f702 276
keyup: f702 276
keydown: f700 273
keyup: f700 273
keydown: f703 275
keyup: f703 275
keydown: f701 274
keyup: f701 274
That the .sym field corresponds to the SDLK_LEFT, UP, RIGHT, and DOWN
is fine, but what puzzles me greatly are the Unicode values. These
are private use area values (), and I am unsure what they mean. I am
not sure who is giving me these values (Macosx? SDL?); have I missed
in the documentation or mailing list what is intended?
This is puzzling because it the code I’m looking at (writ by others)
that does the following on a SDL_KEYDOWN event:
if ((event.key.keysym.unicode && !handle(event.key.keysym.unicode)) ||
(!event.key.keysym.unicode && !handle(event.key.keysym.sym))) {
// handle unhandled stuff
}
where handle above takes the value, and tries to make it up to various
SDLK_ values. But SDLK_LEFT,RIGHT,UP,DOWN will never be sent to
handle: the unicode always has a value (because this is an app that
wants to be internationalized, and has SDL_enableUnicode on).
So maybe I’m asking for advice: should I try to handle the
"command-like" non-printing characters first before anything else? Is
there a pattern used here? Any information appreciated.
cheers,
nigel