Ctrl-c to quit program doesn't work?

Hello all,

My SDL application doesn’t appear to be reacting to ctrl-c. Why is this, and
how can I fix it?

Regards,

Pieter Hulshoff

The SDL window will plain ignore most such combinations. (Depends on
how the OS handles such combinations.) You have to decode the
keyboard events yourself if you want the SDL window to respond to
CTRL+C and the like.

For SIGINT and the like to be sent to a normal SDL application, you
have to do the keystrokes in the console you started the SDL
application from; not in the SDL window. If you’re not running the
application from a console, you’ll have to use whatever means the
desktop environment provides for doing this.

//David Olofson - Programmer, Composer, Open Source Advocate

.- Audiality -----------------------------------------------.
| Free/Open Source audio engine for games and multimedia. |
| MIDI, modular synthesis, real time effects, scripting,… |
`-----------------------------------> http://audiality.org -’
http://olofson.nethttp://www.reologica.se —On Monday 21 March 2005 11.17, Pieter Hulshoff wrote:

Hello all,

My SDL application doesn’t appear to be reacting to ctrl-c. Why is
this, and how can I fix it?

How exactly should I do this? I’ve tried a simple reporting of the key events,
but a ctrl+c from the console is not detected from within the program. What
type of SDL events should this fall under?

Regards,

Pieter HulshoffOn Monday 21 March 2005 12:03, David Olofson wrote:

The SDL window will plain ignore most such combinations. (Depends on
how the OS handles such combinations.) You have to decode the
keyboard events yourself if you want the SDL window to respond to
CTRL+C and the like.

A Ctrl+C from a console (say, in Linux) usually sends an “SDL_QUIT” event
to your app, so just look out for those and handle them appropriately.

(Window manager events can cause SDL_QUIT events as well. For example,
clicking a window’s ‘close’ button in the title bar, or selecting
"Close" from a right-click menu on the window’s taskbar entry.)

-bill!On Mon, Mar 21, 2005 at 04:03:35PM +0100, Pieter Hulshoff wrote:

How exactly should I do this? I’ve tried a simple reporting of the key events,
but a ctrl+c from the console is not detected from within the program. What
type of SDL events should this fall under?

What type of SDL events should this fall under?

while (SDL_PollEvent(&event)) {
switch(event.type) {
case SDL_KEYDOWN:
break;
case SDL_KEYUP:
break;
case SDL_QUIT:
// SDL caught termination signal.
cerr<<“Termination signal caught, exiting.”<<endl;
exit(1);
break;
default:
break;
}
}

CTL^C should generate termination signal, which can be caught with
SDL_QUIT. This works for me, both on FreeBSD and GNU/Linux.

Happy hacking,

-Juan D. Espinoza

Works like a charm. Thanx for the help. :slight_smile:

Regards,

Pieter HulshoffOn Monday 21 March 2005 19:24, Jack Doe wrote:

CTL^C should generate termination signal, which can be caught with
SDL_QUIT. This works for me, both on FreeBSD and GNU/Linux.