Subject: RE: Problem with GetKeyState()
From: [email-masked] (Colin Peters)

6 Nov 1997 21:32:32 -0800
Message-ID: <01BCEB62.27051C60.cygnus.gnu-win32@gbird0>
Mime-Version: 1.0
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit
To: GBradfor <[email-masked]>
Cc: "[email-masked]" <[email-masked]>

$Bill Luebkert[SMTP:[email-masked]] wrote:
>GBradfor wrote:
>>      As I understand the documentation on this function, GetKeyState() takes the
>>      ASCII code for A-Z, a-z, and 0-9 as input (the virtual-key code for
>>      others).  It returns a value where the high-order bit is set for key down,
>>      and it is reset for key up.  The low-order bit is set and reset for
>>      "toggle-able" keys.

However the state returned by this function is the state associated with the
last key message read from the thread's message queue. It is not necessarily
the state of the physical keyboard at the time. It is also not in any way
clear what might be going on if this is called from a console application.
I expect that it will never report any key being down, but I could be wrong.

Basically this function is meant to be used when processing messages to a
window in a GUI program, especially keyboard messages.

You could try using GetAsyncKeyState, but I think that might have similar
problems. Otherwise it may just be a fact of life that console applications
don't get the same level of control over their input and output as GUI
applications.

>I don't claim to be an expert or anywhere close to it, but 
>methinks this routine is only valid when running as a 
>Windows task (not in console mode).  Course I don't know 

Technically a console application is just as much a windows
task as a GUI application... but that's picking nits... :)

Colin.

-- Colin Peters - Saga Univ. Dept. of Information Science
-- [email-masked] - finger for PGP public key
-- http://www.fu.is.saga-u.ac.jp/~colin/index.html
-- http://www.geocities.com/Tokyo/Towers/6162/

-
For help on using this list (especially unsubscribing), send a message to
"[email-masked]" with one line of text: "help".