2

I have a system with no keyboard. I can connect a keyboard, but ultimately the inputs come from a custom keypad which is not a HID device, it sends serial data which I can interpret and decode to determine if the user pressed Up, Down, Left, Right, or Enter.

Right now all I have is a Fl_Window, with two Fl_Button widgets. Focus is set for one of the buttons and callbacks are defined for these buttons. I know that if I attach a real keyboard, and use the arrow keys I can change focus from button to button. I do have to hit SPACE to activate a button.

My problem is determining how to cause these key presses using code when I decode the outcome form the embedded key pad. Because in deployment, there will be no actual keyboard.

What I've tried is to invoke int Fl_Window::handle(int) and not really had success. I've also tried to invoke int Fl::handle(int, Fl_Window *) and not had success.

Here are code examples:

if((ret = Fl::handle(FL_Left, window)) == 0)

That compiles, but I find that I get zero back, implying that it did not process the event.

if((ret = Fl_Window::handle(FL_Right)) == 0)

That does not compile, informing me that it "cannot call member function virtual int Fl_Window::handle(int) without object"

I'm thinking that the "int event" actually ought to be FL_KEYDOWN.

That logic leaves me to wonder though how I "set" event_key(). For instance, there are API functions to get that when one has a handler, but I do not wish to get that; I wish to cause that event to occur.

Is my only option here to figure out how to emulate a HID or make some type of virtual HID where I then cause the keyboard events to occur?

I do not feel I require a handler function in my application, I'm fine with the default behaviors which occur and cause my callback functions to be invoked. My problem is that I can't "cause" these events to occur.

RTM
  • 31
  • 4
  • 1
    Have a look at "Demonstrate keyboard press/release" in http://seriss.com/people/erco/fltk/#KeyPressRelease – cup Mar 07 '14 at 12:31
  • You can cause the events to occur by using send. – cup Mar 07 '14 at 13:35
  • Thanks for citing the example, I think it shows how to write a custom handler, I don't believe I need that, I just need to know how to cause the events to occur. I see the next comment about send(); and the FLTK documentation states that it is the preferred wrapper for handle(). OK, in trying to use that I can't quite find the syntax, nor any examples. I can't get it to compile if I declare it as Fl_Widget::send(), Fl_Window::send(), or Fl::send(). – RTM Mar 07 '14 at 15:52
  • 1
    Sorry: I'm switching between FLTK1 and FLTK2. send is an FLTK2 thing. On FLTK1, send is a static. One way around it is to get the fltk source and take off the static. Another way is to set Fl::e_keysym and then call the handler. Let me know if you need an example - are you using Linux or Windows? – cup Mar 07 '14 at 18:15
  • 1
    Sure an example would be great, I will try this suggestion. I'm using Linux. There's a FLTK2? Maybe I'll switch to that. Checking that out now, my main desire with that one would be if it can work directly to the framebuffer. – RTM Mar 07 '14 at 18:31
  • 1
    I got it working by setting the e_keysym. Thanks for the assist! – RTM Mar 07 '14 at 18:36
  • 1
    There is an FLTK2 and an FLTK3. Hardly anyone uses FLTK2 - if you use it, you're on your own. I have yet to try FLTK3. If you want help on FLTK, best keep to FLTK1. – cup Mar 07 '14 at 18:55

1 Answers1

1

You need to assign the desired key to e_keysym, then dispatch a FL_KEYDOWN event using Fl::handle_(). (Fl::handle() will not generate the followup FL_SHORTCUT event.)

Fl::e_keysym = FL_Left;
Fl::handle_(FL_KEYDOWN, window);
// sleep() and/or Fl::wait() as appropriate
Fl::handle_(FL_KEYUP, window);
Nicholas
  • 628
  • 1
  • 11
  • 14