跳转至内容

FLTK/禁用 Escape 键

来自维基文库,面向开放世界的开放书籍

按下 Escape 键时,FLTK 应用程序会自动退出。若要禁用主窗口上的此行为,自定义回调必须替代默认回调

#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();
}
华夏公益教科书