Hi Geert,
Support for using arrow keys as item shortcuts in Fl_Sys_Menu_Bar
has been added to the FLTK git repository (63dcdce).
Please, pull this last change for your app.
But, you also have to attach the callback function to each menu item
as shown in the modified example program copied below
(I have also added items using the left and right arrows ).
The program also shows the use of fl_shortcut_label() useful to get a
printable representation of menu item shortcuts.
#include <FL/Fl.H>
#include <FL/Fl_Choice.H>
#include <FL/Fl_Double_Window.H>
#include <FL/Fl_Sys_Menu_Bar.H>
#include <FL/fl_draw.H>
#include <stdio.h>
void item_cb(Fl_Widget* w, void *name) {
Fl_Menu_* mw = (Fl_Menu_*)w;
const Fl_Menu_Item* m = mw->mvalue();
if (!m)
printf("NULL\n");
else if (m->shortcut())
printf("%s - %s\n", m->label(), fl_shortcut_label(m->shortcut()));
else
printf("%s\n", m->label());
}
Fl_Menu_Item menutable[] = {
{"&File",0,0,0,FL_SUBMENU},
{"item-up",FL_Up, item_cb},
{"item-down",FL_Down, item_cb},
{"item-left",FL_Left, item_cb},
{"item-right",FL_Right, item_cb},
{0},
{0}
};
Fl_Menu_Item menu_location[] = {
{"Fl_Menu_Bar", 0, 0, 0, FL_MENU_VALUE},
{"Fl_Sys_Menu_Bar", },
{0}
};
Fl_Sys_Menu_Bar* smenubar;
void menu_location_cb(Fl_Widget* w, void* data)
{
Fl_Menu_Bar *menubar = (Fl_Menu_Bar*)data;
if (((Fl_Choice*)w)->value() == 1) { // switch to system menu bar
menubar->hide();
smenubar = new Fl_Sys_Menu_Bar(0,0,0,30);
smenubar->menu(menutable);
}
else { // switch to window menu bar
menubar->menu(menutable);
smenubar->clear();
delete smenubar;
menubar->show();
}
}
/*void test_cb(Fl_Widget* w, void*) {
puts("test callback called");
}*/
int main(int argc, char **argv) {
Fl_Double_Window window(250,150);
Fl_Menu_Bar menubar(0,0,250,25);
menubar.menu(menutable);
// menubar.callback(test_cb);