How do I grab key events in a TRootEmbeddedCanvas?

In a small Root GUI application I’m writing, I want to grab and inspect KeyPress events. After some searching effort, I managed to find the basic solution in the Root Talk archives. In particular, the attachment test1.h shows a greatly simplified version of what I’ve done. It works just fine if I compile with ACLiC and run from the Root Interpreter:

root [0] .L test1.h+
Info in TUnixSystem::ACLiC: creating shared library /home/krlynch/temp/root/keypressed/./test1_h.so
root [1] new TestFrame(gClient->GetRoot(), 100, 100)
(class TestFrame*)0x8898870

I get my window, and regardless of how I interact with it (moving, clicking on various subwidgets, etc), all the KeyPress events I send it print out just fine, and hitting Escape closes the window, as desired.

I run into a problem when I include a TRootEmbeddedCanvas (see attachment test2.h). As soon as I move the mouse into the Canvas area, KeyPress events no longer print out until I move to some non-Canvas part of the window. In the example, I’ve even tried to Connect the relevant signals and slots for the Canvas and my simple class, but that doesn’t seem to work the way I was expecting. I get no complaints from the system about missing slots or signals, as happens when I screw up a Connect call (which is fairly often :-). It seems the Signals and Slots and member functions I call all exist, but they’re not communicating in the way I expected.

I suspect I am missing something crucial. Can anyone see what I am doing wrong here? Does the TRootEmbeddedCanvas widget not support what I’m trying to do? Any pointers would be appreciated.

Root Version: 5.17.02 and 5.18.00 (locally compiled)
OS: Linux 2.6.23.8-63.fc8 #1 SMP i686
Compiler: gcc 4.1.2
test2.h (1.33 KB)
test1.h (1011 Bytes)

Hi,
The problem comes from the fact that the TRootEmbeddedCanvas grab the focus… I will see if there is a simple solution to your problem and let you know.
Bertrand.

In fact the solution is simple:
change:

rec->Connect("ProcessedEvent(Event_t*)", "TestFrame", this, "PrintKey(Event_t*)"); by:

  rec->GetContainer()->Connect("ProcessedEvent(Event_t*)", "TestFrame", 
                this, "PrintKey(Event_t*)");

And you can remove "rec->AddInput(kKeyPressMask);"
Note the GetContainer() statement. Events are processed by the container, not by the canvas itself.

Bertrand.

Brilliant, it works like a charm! Thanks for your help.