Function reading the keyboard-buffer?

Hello Rooters,

I was wondering wether there is a function that reads the keyboard buffer.
The problem is the following:

I have a program running through datafiles, analyzing them. If a certain condition is met I want to pause the program until a keyboard key is hit. Meanwhile I want to plot a histogram in a Canvas.
I was thinking about a pause function like this (very dirty, because its just a thought):

void myCustomClass::pause() { TCanvas *mycan = new TCanvas("p","t",5); mycan->cd(); hist->Draw() // hist is defined elsewhere in this class bool kbhit=false; while(!kbhit) { gSystem->ProcessEvents(); kbhit = kbbufferisfull() // this is the function that I am looking for gSystem->Sleep(50); } delete mycan; }

As you can see, I need a “kbbufferisfull()” function in order for this little function to work. Is there already something that does the job for me, that I was missing during my search? Or is there a better way to accomplish what I am trying to do?

Thank you


Hi Lutz,
there are two cases:

  1. handling keys from console
    You can use TApplication:KeyPressed signal … KeyPressed

  2. handling keys in TCanvas
    You can use … essedEvent

Check also … #first_hit

Regards. Valeriy

Hi Valeriy,

if I understand you and the documentation right both of these ways are working with events. Meaning that I have to write a function that is looking for a keyboard event, or I use the SIGNAL/SLOT mechanism.

What I am looking for is a way to poll the status of the Keyboard Buffer. An eqivalent function would be
_kbhit() from conio.h

Is there something like this in root?

Thank you


Hi Lutz,
AFAIK, no kbhit is available.
I would recommend to emulate it
with “no echo” mode … etEchoMode

Regards. Valeriy