FLTK logo

Re: [fltk.general] Re: Losing keyboard input under user 'spamming' input

FLTK matrix user chat room
(using Element browser app)   FLTK gitter user chat room   GitHub FLTK Project   FLTK News RSS Feed  
  FLTK Apps      FLTK Library      Forums      Links     Login 
 All Forums  |  Back to fltk.general  ]
 
Previous Message ]New Message | Reply ]Next Message ]

Re: Re: Losing keyboard input under user 'spamming' input Ian MacArthur Sep 24, 2021  
 

On Thursday, 23 September 2021 at 18:20:35 UTC+1 spitzak wrote:
I believe this is some stupidity by the X11 developers, instead of making keys repeat as they used to, X reports many key down/up pairs. There is a workaround added, I believe, to the fltk2.0 code, this needs to be copied into fltk1. Basically in the event handling when it gets a key-up, it needs to check if there is a key-down for the same key queued and instead turn it into only a repeating key-down event.

Yeah - what Bill said; peeking ahead in the queue  and eliding any KEYUP that is immediately followed by the same KEYDOWN might be the only robust solution?
Dunno...

Interestingly, I actually looked at the docs for Keyboard Events, and it includes this exhortation:

Todo: Add details on how to detect repeating keys, since on some X servers a repeating key will generate both FL_KEYUP and FL_KEYDOWN, such that to tell if a key is held, you need Fl::event_key(int) to detect if the key is being held down during FL_KEYUP or not.

I don't know who wrote that (I'm fairly sure it was not me, at any rate!) but that sounds like exactly the thing... Might be worth a try.

Meanwhile, in the interests of completeness, I added the timer check I proposed earlier. This appears to work just fine (On Windows) but today's another non-Linux day for me, so can't readily test under X11...

//////////////////////////////////
#include <FL/Fl.H>
#include <FL/Fl_Double_Window.H>
#include <FL/Fl_Menu_Bar.H>

static int shown_v = 0;
/*****************************************************************************/
static bool still_pressing = false;
static bool timeout_active = false;
static void check_timeout (void *pv)
{
    if (still_pressing == true)
    {
        still_pressing = false;
        Fl::add_timeout(0.2, check_timeout, pv);
    }
    else
    {
        timeout_active = false;
        Fl_Double_Window *w = (Fl_Double_Window *)pv;
        if (shown_v) {
            w->hide();
            shown_v = 0;
        }
        else {
            w->show();
            shown_v = 1;
        }
    }
} // check_timeout

/*****************************************************************************/

class my_win : public Fl_Double_Window {

    int handle (int);

public:
    my_win(int x, int y,int w,int h,const char* L) : Fl_Double_Window(x,y,w,h,L) {};
}; // my_win

int my_win::handle (int e) {
    int ret = Fl_Double_Window::handle(e);
    if (e == FL_KEYDOWN) {
        if (Fl::event_state() & (FL_ALT)) {
            if (Fl::event_key()=='s') {
                still_pressing = true;
                if (!timeout_active)
                {
                    Fl::add_timeout(0.2, check_timeout, (void *)this);
                    timeout_active = true;
                }
                return 1;
            }
        }
    }
    else if (e == FL_KEYUP) {
        if (still_pressing)
        {
            still_pressing = false;
            return 1;
        }
    }
    return ret;
} // my_win::handle

static void toggle_win (Fl_Widget*,void* data) {
    my_win* w = static_cast<my_win*>(data);

    if (shown_v) {
        w->hide();
        shown_v = 0;
    }
    else {
        w->show();
        shown_v = 1;
    }
} // toggle_win

int main() {
    shown_v = 0;

    my_win *win2 = new my_win(0.5*Fl::w()-100,0.5*Fl::h()-100,200,200,"2nd Win");
    win2->end();

    Fl_Double_Window *win = new Fl_Double_Window(0.5*Fl::w()-200,0.5*Fl::h()-200,400,400,"Main Win");
    win->begin();
    win->box (FL_FLAT_BOX);

    Fl_Menu_Item items[] = {
        {"Menu1",0,0,0,FL_SUBMENU,0,0,FL_NORMAL_SIZE,FL_BLACK}, //0
        {"Hide/show second window",FL_ALT+'s',toggle_win,win2,0,0,0,FL_NORMAL_SIZE,FL_BLACK},
        {0,0,0,0,0,0,0,0,0},
        {0,0,0,0,0,0,0,0,0}
    };

    Fl_Menu_Bar *menu = new Fl_Menu_Bar(0, 0, win->w(),25);
    menu->box (FL_BORDER_BOX);
    menu->menu(items);
    win->end();
    win->show();

    return Fl::run();
} // main
// end of file




--
You received this message because you are subscribed to the Google Groups "fltk.general" group.
To unsubscribe from this group and stop receiving emails from it, send an email to fltkgeneral+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/fltkgeneral/bcce931c-2b85-43c9-ac90-af2d8d16bd87n%40googlegroups.com.
Direct Link to Message ]
 
     
Previous Message ]New Message | Reply ]Next Message ]
 
 

Comments are owned by the poster. All other content is copyright 1998-2024 by Bill Spitzak and others. This project is hosted by The FLTK Team. Please report site problems to 'erco@seriss.com'.