PC Review


Reply
Thread Tools Rate Thread

Check keyboard while in an important loop

 
 
mcm
Guest
Posts: n/a
 
      12th Feb 2009
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

 
Reply With Quote
 
 
 
 
Paul G. Tobey [eMVP]
Guest
Posts: n/a
 
      12th Feb 2009
GetAsyncKeyState(). You'll have to P/Invoke it, of course.

Paul T.

"mcm" <(E-Mail Removed)> wrote in message
news:u5%(E-Mail Removed)...
> 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
>



 
Reply With Quote
 
mcm
Guest
Posts: n/a
 
      13th Feb 2009
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



>GetAsyncKeyState(). You'll have to P/Invoke it, of course.
>
>Paul T.
>
>"mcm" <(E-Mail Removed)> wrote in message
>news:u5%(E-Mail Removed)...
>> 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
>>

>


 
Reply With Quote
 
Paul G. Tobey [eMVP]
Guest
Posts: n/a
 
      16th Feb 2009
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.

"mcm" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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
>
>
>
>>GetAsyncKeyState(). You'll have to P/Invoke it, of course.
>>
>>Paul T.
>>
>>"mcm" <(E-Mail Removed)> wrote in message
>>news:u5%(E-Mail Removed)...
>>> 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
>>>

>>

>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
returning back to loop check condition without completing the loop ashish128 Microsoft Excel Programming 13 3rd Apr 2008 12:53 PM
Loop through column(s) to check values, perform action based on check ward376 Microsoft Excel Programming 4 6th Nov 2007 03:21 PM
Re: Check out this important patch Joe Richards [MVP] Microsoft Access Database Table Design 0 24th Sep 2003 02:03 AM
Re: Check out this important patch Joe Richards [MVP] Microsoft Access Reports 0 24th Sep 2003 02:03 AM
Re: Check out this important patch Joe Richards [MVP] Microsoft Access Security 0 24th Sep 2003 02:03 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:34 AM.