Keyboard input in OSX - why the H... doesn't it work?

Hi all :slight_smile:

This question probably has a trivial answer, but I have to pose it anyway:

Why can’t I get any keyboard input on OSX? The very same code has tested fine on
Linux…

#undef main
int main(int argc, char *argv[]) {

if( SDL_Init(SDL_INIT_TIMER|SDL_INIT_VIDEO) <0 ) {
printf(“Unable to init SDL: %s\n”, SDL_GetError());
return 1;
} atexit(SDL_Quit);

if(SDL_PollEvent(e)) {
if(e->type == SDL_KEYDOWN) {
if (e->key.keysym.sym == SDLK_ESCAPE) {
printf(“bye!\n”);
exit(0);
}
}

Nothing happens when I press escape - the program keeps running in OSX. On
Linux, the program exits, and everything is fine - and other keypresses works
great too… Am I missing something obvious? Or probably more accurately, what
obvious thing am I missing? :slight_smile:

Thanks in advance! -Andreas

Try this:

while(SDL_PollEvent(&event))
{
//if event foo here
}

— buding at daimi.au.dk wrote:> Hi all :slight_smile:

This question probably has a trivial answer, but I have to
pose it anyway:

Why can’t I get any keyboard input on OSX? The very same code
has tested fine on
Linux…

#undef main
int main(int argc, char *argv[]) {

if( SDL_Init(SDL_INIT_TIMER|SDL_INIT_VIDEO) <0 ) {
printf(“Unable to init SDL: %s\n”, SDL_GetError());
return 1;
} atexit(SDL_Quit);

if(SDL_PollEvent(e)) {
if(e->type == SDL_KEYDOWN) {
if (e->key.keysym.sym == SDLK_ESCAPE) {
printf(“bye!\n”);
exit(0);
}
}

Nothing happens when I press escape - the program keeps
running in OSX. On
Linux, the program exits, and everything is fine - and other
keypresses works
great too… Am I missing something obvious? Or probably more
accurately, what
obvious thing am I missing? :slight_smile:

Thanks in advance! -Andreas


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl


Do you Yahoo!?
Friends. Fun. Try the all-new Yahoo! Messenger.

Hi all :slight_smile:

This question probably has a trivial answer, but I have to pose it
anyway:

Why can’t I get any keyboard input on OSX? The very same code has
tested fine on
Linux…

#undef main
int main(int argc, char *argv[]) {
The problem is most probably the stuff above! That’s what you get for
not using the SDL init code you are supposed to include (either via
linkto to libSDLmain, or by including SDLmain.m in your source, or a
modified version).

Without that, the SDL window will not have keyboard focus and hence not
receive any input events.

Conclusion: If you use hackish tricks, you reap hackish results :slight_smile:

Bye,

MaxAm 10.06.2004 um 00:27 schrieb buding at daimi.au.dk: