Detecting key presses in FLTK

Global shortcut handler

See section 6 of the FLTK online manual
Add an event handler function like this to your code:
int keyhandler(int event) {
    if (event == FL_SHORTCUT) {
        if (Fl::event_key() == 'y') {
            //do something because the y key was pressed
            return 1; // to indicate we used the key event
        }  // here you can test for other keys, as wanted
    }
    return 0;  // we had no interest in the event
}
Then hook this function into the event handling loop with a line like this, just before calling Fl::run()
Fl::add_handler(keyhandler);
There are other events you might look for: separate key up and key down events, for example. However, this global handler can't see all events, for example KeyUp events (when a key is released). There are other ways of doing this:

Other possibilities