Check keyboard while in an important loop

M

mcm

I'm stuggling with a seemingly simple issue.

Inside a C# (Windows CE application, I have a function that handles a measurement.
During the measurement, I need to check the keyboard to see if the Escape (27) key has been hit and I can't find a way to do this.
I'd like to look through any buffered keystrokes - remove the ones I'm not interested in and look for an "escape", but I'm not finding any info.

private Boolean HandleMeasurement()
{
Boolean bMeasuring = true;
Boolean bAbort = false;

while (SystemIsMeasuring() && (!bAbort))
{
// load the available data
GetMyData();

// test for keyboard input, if cancel was pressed set bAbort = true
bAbort = IDontHaveAClueHowToDoThis();
}

}

My question: what should the "IDontHaveAClueHowToDoThis()" function look like?

Thanks,

- mcm
 
M

mcm

Thanks Paul,

This looks promising, and works when I attach a physical keyboard to my device.

However, my device has a hardware keypad (series of switches). I handle these switches so that they act like a keyboard through the use of keybd_event calls.

For example, my hardware EXIT button is treated as the escape key via:

keybd_event(0x1B, 0x45, 0, 0); // Esc key

My problem is that software keybd_event's don't seem be be detected with GetAsyncKeyState.
Do I need to do something different with my keybd_event call's so that they can be detected by GetAsyncKeyState?

- mcm
 
P

Paul G. Tobey [eMVP]

You could try GetKeyState(). Generally, though, when you're using
keybd_event(), you're bypassing most of the input processing and so standard
functions won't work as they will with real keyboard drivers.

Paul T.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top