On 08.04.2011 10:42, terry lai wrote: > Now I create a thread to receive command from another a parent and run > GrInjectKeyboardEvent function to inject a key
I don't know what GrInjectKeyboardEvent() does, but I found this: http://www.mail-archive.com/[email protected]/msg00543.html > as command the program to do show hide in process main loop. > > In FLTK, I register the handler by > > > int handle(int e) > { > > cout<<Fl::event_key()<<endl; > : > : > } > : > : Usually this would not be necessary, if this would work somehow like pressing a key. You should get the keypress event in the widget that has input focus, and you should try this first. Did you? Another important point is that your handle() function would only get events that FLTK can't handle otherwise. If this would be a keypress event, then you should see that 'e' is either FL_KEYDOWN or FL_SHORTCUT, and you should really test this in your code. Otherwise, for most or all other events that you might see, Fl::event_key() would be undefined. > static void *commandHandler(void *p) > { > int com; > while(1) > { > if(mq->receive(&com)) > { > } > else > { > break; > } > > switch(com) > { > case 1://home > > > GrInjectKeyboardEvent(fl_xid(mw),'a', 0, 0, 1); > GrInjectKeyboardEvent(fl_xid(mw),'a', 0, 0, 0); > break; > case 2: > GrInjectKeyboardEvent(fl_xid(mw),'b', 0, 0, 1); > GrInjectKeyboardEvent(fl_xid(mw),'b', 0, 0, 0); > break; > } > } > } > > > : > : > int main() > { > : > : > Fl::add_handler(handle); > : > : > pthread_t thread; > pthread_create(&thread, NULL, commandHandler, mw); > > return Fl::run(); > > } > > However, in the handle, I always read Fl::event_key() equal to 0. > > I have tried to inject ascii keys a and b but they all results 0 in handle. > > I do not know why, is it my fault? As written above, please check first, what kind of event you're really getting. It would also be easier to use a timer (see Fl::add_timeout()) instead of threads, and maybe this is also the cause of your problem. You must wake up FLTK's event handling by callling Fl::awake() from time to time, and you would have to call Fl::lock() in your program initialization. But since you didn't show the whole program, this is all only wild guessing... Albrecht _______________________________________________ fltk mailing list [email protected] http://lists.easysw.com/mailman/listinfo/fltk

