Hi Olivier, Valeriy, I made the needed changes in TRoot(Embedded)Canvas::HandleContainerKey() (now in CVS). The following works fine: //------ olivier.C void printKey(Int_t event, Int_t key, Int_t keysym) { // print key and keysym TCanvas *c = (TCanvas *) gTQSender; if(event != kKeyPress) return; printf("symbol = %c (%x)\n", key, keysym); switch ((EKeySym)keysym) { case kKey_Left: cout<<"left arrow"<<endl; break; case kKey_Right: cout<<"rightarrow"<<endl; break; case kKey_Down: cout<<"down arrow"<<endl; break; case kKey_Up: cout<<"up arrow"<<endl; break; } } void olivier() { // Create canvas and connect ProcessedEvent() signal to printKey() slot. TCanvas *c1 = new TCanvas("c1", "Test of Canvas Event Signal",900, 500); c1->Connect("ProcessedEvent(Int_t,Int_t,Int_t,TObject*)", 0, 0, "printKey(Int_t,Int_t,Int_t)"); } root[] .x olivier.C Cheers, Fons. Valeriy Onuchin wrote: > > Hi Olivier, Fons, > the simplest way to handle canvas events(key,mouse ..) is using signal/slots > check the code below: > > ---------------------------- olivier.C ------------------------------ > //___________________________________________________________________ > void printKey(Int_t event,Int_t keysym) > { > // print event type and current cursor position > > TCanvas *c = (TCanvas *) gTQSender; > if(event != kKeyPress) return; > printf("symbol = %c\n",keysym); > } > > //___________________________________________________________________ > void olivier() > { > // > > TCanvas *c1 = new TCanvas("c1", "Test of Canvas Event Signal",900, 500); > c1->Connect("ProcessedEvent(Int_t,Int_t,Int_t,TObject*)",0,0,"printKey(Int_t,Int_t)"); > } > > ---------------------------- olivier.C --------------------------------- > > try it by: > > root[].x olivier.C > > Unfortunately that does not work for special symbols ( up,down,.. ) > I think it can be easily extended by modification of > > Bool_t TRootCanvas::HandleContainerMotion(Event_t *event) > { > // ... > fCanvas->HandleInput(kKeyPress, str[0], keysym); // was fCanvas->HandleInput(kKeyPress, str[0], 0); > // ... > } > > Regards. Valeriy > > Olivier Meplan wrote: > > > Valeriy Onuchin wrote: > > > > > Hi Oliver, > > > check tetris game in $ROOTSYS/test/. > > > It has exactly what you want. THT. > > > > > > Regards. Valeriy > > > > Hi Valeriy, > > Thanks for your answer. I send you a small code ; could you tell me if > > there is a way to do the same thing in a shorter way...because I find it > > quite complicated for very simple things... > > Thanks > > Best Regards, > > Olivier > > ------------ > > > > #include <iostream.h> > > > > #include <TROOT.h> > > #include <TApplication.h> > > #include <TRootCanvas.h> > > #include <TCanvas.h> > > #include <TVirtualX.h> > > #include <KeySymbols.h> > > > > class MyWin : public TCanvas,TGFrame > > { > > public: > > MyWin(); > > void HandleInput(EEventType event, Int_t px, Int_t py); > > Bool_t HandleKey(Event_t *event); > > }; > > > > MyWin::MyWin():TCanvas("c","",400,400),TGFrame(gClient->GetRoot(),0,0) > > { > > > > TRootCanvas *main_frame=(TRootCanvas*)GetCanvasImp(); > > main_frame->BindKey(this, > > gVirtualX->KeysymToKeycode(kKey_Up),kAnyModifier); > > main_frame->BindKey(this, > > gVirtualX->KeysymToKeycode(kKey_Left),kAnyModifier); > > main_frame->BindKey(this, > > gVirtualX->KeysymToKeycode(kKey_Right),kAnyModifier); > > main_frame->BindKey(this, > > gVirtualX->KeysymToKeycode(kKey_Down),kAnyModifier); > > } > > Bool_t MyWin::HandleKey(Event_t *event) > > { > > char tmp[2]; > > UInt_t keysym; > > gVirtualX->LookupString(event, tmp, sizeof(tmp), keysym); > > > > if (event->fType == kGKeyPress) { > > switch ((EKeySym)keysym) { > > case kKey_Left: > > cout<<"left arrow"<<endl; > > break; > > case kKey_Right: > > cout<<"rightarrow"<<endl; > > break; > > case kKey_Down: > > cout<<"down arrow"<<endl; > > break; > > case kKey_Up: > > cout<<"up arrow"<<endl; > > break; > > default: > > return kTRUE; > > } > > } > > return kTRUE; > > } > > void MyWin::HandleInput(EEventType event, Int_t px, Int_t py) > > { > > TCanvas::HandleInput(event,px,py); > > switch (event) > > { > > > > case kButton1Down: > > cout<<"left clic"<<endl; > > break; > > case kButton3Down: > > cout<<"right clic"<<endl; > > break; > > case kKeyPress: > > cout<<"the key pressed is : "<<char(px)<<endl; > > break; > > } > > > > } > > int main(int argc, char **argv) > > { > > TROOT root("root","tttt"); > > TApplication TheApp("TheApp",&argc, argv); > > MyWin *mywin=new MyWin(); > > TheApp.Run(); > > return 0; > > } -- Org: CERN, European Laboratory for Particle Physics. Mail: 1211 Geneve 23, Switzerland E-Mail: Fons.Rademakers@cern.ch Phone: +41 22 7679248 WWW: http://root.cern.ch/~rdm/ Fax: +41 22 7677910
This archive was generated by hypermail 2b29 : Tue Jan 01 2002 - 17:50:41 MET