Re: Re: Losing keyboard input under user 'spamming' input
rs
Sep 24, 2021
Thanks for the suggestions, Ian.
FYI, the first managed to avoid the issue entirely (albeit with the 0.2 second delay). The second still causes the keyboard events to fall over if the button is held down long enough.
Thanks,
R.
On Friday, September 24, 2021 at 6:24:28 PM UTC+10 Ian MacArthur wrote:
On Friday, 24 September 2021 at 08:57:20 UTC+1 Ian MacArthur wrote:
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.
And for (even more!) completeness, here's what I think that might mean - though given that I'm not on X11 today I have no clue of this will work or not.
Works. OK on Win10, but that's not all that helpful in this instance...
////////////////////////////
#include <FL/Fl.H>
#include <FL/Fl_Double_Window.H>
#include <FL/Fl_Menu_Bar.H>
static int shown_v = 0;
class my_win : public Fl_Double_Window {
int handle (int);
int please_change;
public:
my_win(int x, int y,int w,int h,const char* L):Fl_Double_Window(x,y,w,h,L), please_change(0) {};
}; // 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') {
please_change = (-1);
return 1;
}
}
}
else if (e == FL_KEYUP) {
if (please_change) {
if ((Fl::event_state() & FL_ALT) && (Fl::event_key() == 's')) {
// Probably a synthetic repeat keyup on X11? Ignore...
return 1;
}
else { // Assumed to be a real keyup
please_change = 0;
if (shown_v) {
this->hide();
shown_v = 0;
}
else {
this->show();
shown_v = 1;
}
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");
Comments are owned by the poster. All other content is copyright 1998-2025 by Bill Spitzak and others. This project is hosted by The FLTK Team. Please report site problems to 'erco@seriss.com'.