FLTK/Disabling the escape key
Appearance
< FLTK
FLTK applications automatically exit when pressing the Escape key. To disable this behaviour on the main window, a custom callback must replace the default one:
#include <fltk/events.h>
#include <fltk/run.h>
#include <fltk/Window.h>
#include <cstdlib>
void window_callback (fltk::Widget*) {
if (fltk::event() == fltk::KEY && fltk::event_key() == fltk::EscapeKey) {
// don't do anything when the Escape key is pressed
} else {
// exit when the user closes the window
exit(0);
}
}
int main (int argc, char** argv) {
fltk::Window window (300, 300, "FLTK test");
// set our own callback
window.callback (window_callback);
window.show (argc, argv);
return fltk::run();
}