> To get key events your widget must return 1 on FL_PUSH and FL_FOCUS 
> events. I don't think that Fl_Box::handle() would do this, so you'd 
> better add this in your handle() method. Then you must click once in 
> your canvas, and your widget should get key events.

Here's a working example (use it in your first version).

int Canvas::handle(int event) // handle the event
{
   switch(event)
   {
     case FL_KEYBOARD:
       switch(Fl::event_key())
       {
        case FL_Right:
          XC = XC + 1;
          YC = YC + 1;
          redraw();
          return 1;
        case FL_Left:
          XC = XC - 1;
          YC = YC - 1;
          redraw();
          return 1;
        default:
          return 1; // "eat" all other keys !
       }
     case FL_FOCUS:
     case FL_PUSH:
       return 1;

     default:
       return Fl_Box::handle(event);
   }
}

The "return 1" with the comment '"eat" all other keys' prevents that all 
other keys are delivered as FL_SHORTCUT events to other widgets. You can 
also return 0 here, YMMV.

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

Reply via email to