Howto use SIGNAL KeyPressed(int) to prevent Keyboard input?

Hello Rooters,

I have written a small macro using the signal/slot machanism (See below). Using the Signal KeyPressed(int) from gApplication I was able to go through an opened root-file and see all the histograms with the ‘+’ and the ‘-’ Keys.
Now the question:
How do I prevent the ‘+’ or the ‘-’ Charakter to be printed in the Console? Is there something like “if key is + don’t plot charakter on console”?

Thank you
Lutz

///////////toggle macro///////////////////////////////
void execEvent(Int_t keyb)
{
    static int keynum;
    if (!gDirectory->GetNkeys()) return;
    if (keyb ==45) //minus
    {
        if (keynum > 0) --keynum;
    }
    else if (keyb==43) //plus
    {
        if (gDirectory->GetNkeys()-1 > keynum) ++keynum;
    }
    else if (keyb==115) // key 's'
    {
        cout<<"exiting"<<endl;
        gApplication->Disconnect();
        return;
    }
    else
    {
        return;
    }
    TCanvas *c0	= gPad->GetCanvas();
    TKey *key = gDirectory->GetListOfKeys()->At(keynum);
    TObject *obj = key->ReadObj();
    if ( obj->IsA()->InheritsFrom( "TH1" ) )
    {
        TH1 *h1 = (TH1*)obj;
        h1->Draw();
        c0->Modified();
        c0->Update();
    }
    delete obj;
}

void toggle()
{
    gApplication->Connect("KeyPressed(Int_t)",0,0,"execEvent(Int_t)");
}

Hi Lutz,
in principal it’s possible to add
TApplication::SetConsoleMode method which
would allow to set “noecho” mode.
After that you could connect a filter function to
TApplication:: KeyPressed(Int_t key) signal

Filter function would have a code like …

if ((key==’+’) || (key==’-’)) return;
else putc(key);

Regards. Valeriy

Hi Valeriy,

I was just checking the latest version of root (4.0/04).
There was no such method.
Did you impliment it?
I am sorry but I am not experienced enough to add something like this.

Thank you

Lutz

Hi Lutz,
I sent the code to Rene and Fons.
Unfortunately it was not comitted in 4.04

You can use a patch at attachment.

Thanks. Regards. Valeriy
noecho.diff.txt (3.14 KB)

Hi Lutz, now in CVS.

Regards. Valeriy