FL_KEYDOWN event will be received many times if a key is held down.
It is not good to capture the screen again and again for a single pressing. I
need to detect FL_KEYUP when the PrintScreen key is up.
But I can only capture FL_KEYDOWN for Fl_Print.
Here is the test code:
#include <FL/Fl.H>
#include <FL/Fl_Widget.H>
#include <FL/Fl_Double_Window.H>
#include <FL/fl_draw.H>
#define DELAY 0.01
#include <sys/time.h>
Fl_Offscreen oscr = 0;
class Test_Draw: public Fl_Widget {
public:
Test_Draw(int x, int y, int w, int h, char *l=0):Fl_Widget(x,y,w,h,l) {
}
void draw() {
if(!oscr) oscr = fl_create_offscreen(Fl::w(),Fl::h());
static int d=0;
d++;
fl_begin_offscreen(oscr);
fl_rectf(x(),y(), (int) d%w(), (int)d%h(), d%255,d%255,d%255);
fl_end_offscreen();
fl_copy_offscreen(x(),y(),w(),h(),oscr,x(),y());
}
int handle(int e) {
switch (e) {
case FL_KEYUP:
if ( Fl::event_key(FL_Print) ) printf("ok\n");
break;
}
return(Fl_Widget::handle(e));
}
};
Test_Draw *t;
static void update(void *)
{
t->redraw();
Fl::repeat_timeout(DELAY, update,0);
}
int main(int argc, char **argv) {
Fl_Window w(200,200,Fl::w()/2, Fl::h()/2);
t = new Test_Draw(0,0,w.w(),w.h());
Fl::focus(t);
w.end();
w.resizable(&w);
w.show(argc, argv);
Fl::repeat_timeout(DELAY, update,0);
return(Fl::run());
}
_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk