>
> It seems that a button's callback can't be attached
> to pressing the enter key.  Is that true?

Looks to me from the Fl_Button source, and from this documentation  
http://www.fltk.org/doc-1.1/Fl_Button.html#Fl_Button.when, that Fl_Button is 
not currently set up to respond to the enter key.

However if you write a simple class inheriting from Fl_Button I think you can 
solve the problem easily.  Heres a modified version of your example to 
demonstrate:

#include <FL/Fl_Double_Window.H>
#include <FL/Fl.H>
#include <FL/Fl_Button.H>
#include <FL/fl_ask.H>

void btn_cb(Fl_Widget*, void*)
{
        fl_alert("Hello");
}

class mybutton : public Fl_Button{
public:
mybutton(int x,int y,int w,int h,const char *n):Fl_Button(x,y,w,h,n){}
int handle(int event){
if(event==FL_KEYDOWN)
if(Fl::event_key()==FL_Enter)
if(when()&FL_WHEN_ENTER_KEY_ALWAYS){
do_callback();
return 0;
}
return Fl_Button::handle(event);
}

};

int main()
{
        Fl_Double_Window win(300, 300);
        //Fl_Button* btn = new Fl_Button(50, 50, 20, 100, "button");
        mybutton *btn=new mybutton(50, 50, 20, 100, "button");
        Fl_Button *btn2=new mybutton(120,50,20,100,"button 2");
        win.end();

        btn->callback(btn_cb);
        btn->when(FL_WHEN_ENTER_KEY_ALWAYS | FL_WHEN_RELEASE_ALWAYS);

        btn->take_focus();

        win.show();
        return Fl::run();
}


_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk

Reply via email to