Event_t and key code

Hi,

I am interested in the key pressed events occuring on a TGCanvas.
I have a piece of code like that :

fCanvas = new TGCanvas(this, 100, 100);
   
   fListTree = new TGListTree(fCanvas, kHorizontalFrame);

//[snip]
   
   fCanvas->GetViewPort()->GetContainer()->Connect("ProcessedEvent(Event_t*)", "TAmoreObjectManager", TAmoreObjectManager::GetInstance(), "HandleFileBrowserEvents(Event_t*)");

Then my slot is :

void TAmoreObjectManager::HandleFileBrowserEvents(Event_t *event)
{
   if (event->fType != kGKeyPress) {
      return;
   }
      cout << "event : " << event->fCode << " " << event->fState << endl;
}

When I hit ‘a’, it prints “event : 38 20”. However I expected the fCode to be 97. What really surprises me is that the key corresponding to 39 is not ‘b’ but ‘s’. In fact, the fCode is related to the place of the key on the keyboard !

Is it a feature ?
Anyway, how can I get a code corresponding to the char which has been hit ? Like 97 for ‘a’, 98 for ‘b’ , etc… ?

Thanks in advance for your help,

Barth

Hi Barth,

Sorry, but I can’t reproduce the problem…Here is what I get (from a to z):

event : 97 0 event : 98 0 event : 99 0 event : 100 0 event : 101 0 event : 102 0 event : 103 0 event : 104 0 event : 105 0 event : 106 0 event : 107 0 event : 108 0 event : 109 0 event : 110 0 event : 111 0 event : 112 0 event : 113 0 event : 114 0 event : 115 0 event : 116 0 event : 117 0 event : 118 0 event : 119 0 event : 120 0 event : 121 0 event : 122 0
Cheers,
Bertrand.

Hi Bertrand,

I attach a modified version of your example DND_dev. I added a slot “asdf” in MyClass and connected the signal of the TGCanvas containing the tree to this slot.

The output is the same as the one I explained in my first message. If you put the mouse over the tree and type ‘a’ you will get “38 16”… and then if you move the mouse it continues to produce the same event… which is strange as well.

I am sure I am doing a stupid mistake, but I don’t see what it is.

Thanks in advance,

Barth

PS:
the makefile can’t be attached, but it is strictly the same as the one you sent to me.
rdnd2.cxx (20.1 KB)
MyClass.h (483 Bytes)
LinkDef.h (160 Bytes)

Hi Barth,

OK, I see… it works on Windows (the reason why I didn’t see the problem yesterday) but not on Linux…
I investigate.

Cheers,
Bertrand.

OK, I’m using too much Windows… :wink:
Here is the solution to your problem:

[code]//______________________________________________________________________________
void MyClass::asdf(Event_t *event)
{
char input[10];
UInt_t keysym;

if (event->fType != kGKeyPress) {
return;
}
gVirtualX->LookupString(event, input, sizeof(input), keysym);
std::cout << "event : " << event->fCode << " " << event->fState
<< "; " << keysym << std::endl;
}[/code](using gVirtualX->LookupString(event, input, sizeof(input), keysym);)
And sorry for the trouble :blush:

BTW, you can also use TGListTree::KeyPressed(TGListTreeItem *entry, UInt_t keysym, UInt_t mask); signal…

Cheers,
Bertrand.

Thanks for your help !

Cheers,

Barth

Hi,

I have the same question but for a TCanvas.
I connect a slot to the signal of a TCanvas :

myTCanvas>Connect("ProcessedEvent(Int_t , Int_t , Int_t , TObject *)",
                                         "TAmoreObjectManager", this,
                                         "HandleCanvasEvents(Int_t , Int_t , Int_t , TObject *)");

And my slot is

void TAmoreObjectManager::HandleCanvasEvents(Int_t event, Int_t x, Int_t y, TObject *selected)
{
   if (event != kButton1Up && event != kButton1Double && event != kKeyPress)
               return ;
            
   cout << "event : " << event << " ; x : " << x << " ; y : " << y << endl;

   // here I would like to know if the ctrl key is used or not. 
}

And as a result I get event = 24 for the key events (that’s fine), and the ascii code in both x and y variables for a a simple key stroke. But if I use the ctrl modifier then I get x=26 and y=122 per instance for Ctrl-z. Moreover a hit on the delete key gives me x=127 and y=4103.
As a consequence, I am wondering if there is a clean way of knowing if a modifier key is used.

Thanks in advance

Barth

Hi Barth,

Sorry, brom TCanvas, the only available modifier/button state combination is Shift+kButton1Motion (and not really documented :blush: ):

if (fButton == kButton1) { if (event->fState & kKeyShiftMask) fCanvas->HandleInput(EEventType(8), x, y);
Please don’t ask me why it is like this…

Cheers,
Bertrand.