I need to immediately detect when Caps Lock is turned on or off in our 
login screen, so I can alert the user. Neither of the approaches I've 
tried works.

Both the overrides of Fl_Window::handle and Fl_Secret_Input::handle 
don't report that Caps Lock has been turned off until the message after 
it's been turned off.

Here's the below sample program's output for the transition from Caps 
Lock on to off.

   caps lock 7
caps lock 6
caps lock 7
   caps lock 8
   caps lock 9
caps lock 8
   caps lock 10

Howard Rubin

#include <FL/Fl.H>
#include <FL/Fl_Window.H>
#include <FL/Fl_Secret_Input.H>
#include <iostream>

class myWindow : public Fl_Window {
public:
     myWindow(int x, int y, const char* l) : Fl_Window(x, y, l) { }

     virtual int handle(int event) {
         static int n = 0;
         if (Fl::event_state() & FL_CAPS_LOCK) {
             std::cout << "caps lock" << " " << ++n << std::endl;
         } else {
             std::cout << "caps unlock" << " " << ++n << std::endl;
         }
         return Fl_Window::handle(event);
     }
};

class mySecretInput : public Fl_Secret_Input {
public:
     mySecretInput(int x, int y, int w, int h, const char *l)
         : Fl_Secret_Input(x, y, w, h, l) { }

     int handle(int event) {
         static int n = 0;
         if (Fl::event_state() & FL_CAPS_LOCK) {
             std::cout << "  caps lock" << " " << ++n << std::endl;
         } else {
             std::cout << "  caps unlock" << " " << ++n << std::endl;
         }
         return Fl_Secret_Input::handle(event);
     }
};

int main(int argc, char* argv[]) {
     myWindow* win = new myWindow(300, 200, "");

     mySecretInput* inp = new mySecretInput(20, 20, 100, 15, "");

     win->end();
     win->show();

     return Fl::run();
}


_______________________________________________
fltk mailing list
fltk@easysw.com
http://lists.easysw.com/mailman/listinfo/fltk

Reply via email to