Suspending keyboard input to CINT

Hello,

I installed a keyboard handler in the usual signal/slot way:

  gApplication->Connect("KeyPressed(int)","A",a,"b(int)");

This works, i.e. a->b() is called as expected for every character pressed. However I find that the keyboard input is simultaneously still being delivered to CINT, e.g. if I type “.q\n” this quits the session, and also after A::b() disconnects itself, the current interpreter input line is everything that has been typed so far.

Is there some way to temporarily suspend input to CINT so that my function can be the exclusive KeyPressed handler? Or even if I could just clear the CINT input buffer manually that would be sufficient.

Thanks,

Sue Ann Koay
sakoay@cern.ch

Hi Sue Ann,

couldn’t you simply call Getlinem() yourself?

Cheers, Axel.

I tried using Getlinem(), but the reason for using TApplication::KeyPressed() in the first place was so that ROOT can continue processing GUI events such as interaction with canvases until the user presses a key. I thought that Getlinem(kOneChar) can do this, but it seemed to be a blocking operation so I gave it up… maybe my memory is fuzzy though?

Hi

Since you’re already using the GUI, why not using a dialog, as shown in the example code below?

[code]
TH1F *h1 = 0;

void NextHisto(const char *command)
{
cout<<command<<endl;
if (command[0]==‘q’) gApplication->Terminate(0);
if (h1) {
h1->FillRandom(“gaus”, 10000);
h1->Draw();
}
}

void UserInput()
{
char command[80];
h1 = new TH1F(“h1”, “histo from a gaussian”, 100, -3, 3);
h1->FillRandom(“gaus”, 10000);
h1->Draw();
printf("\nDouble click in the bottom right corner of the pad to continue\n");
while (1) {
h1->FillRandom(“gaus”, 10000);
gPad->Modified();
gPad->Update();
gPad->WaitPrimitive();
new TGInputDialog(gClient->GetDefaultRoot(), gClient->GetDefaultRoot(),
“Please type a command:”, “q”, command);
cout<<command<<endl;
if (command[0]==‘q’) gApplication->Terminate(0);
}
} [/code]
But note that this method is also waiting for the users input, as TGInputDialog is “modal”…
One solution would be to create your own “non-modal” dialog, and using signal-slots to get the users input.

Cheers, Bertrand.