This is the mail archive of the cygwin@sourceware.cygnus.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

RE: Problem with GetKeyState()


$Bill Luebkert[SMTP:dbe@wgn.net] 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
-- colin@bird.fu.is.saga-u.ac.jp - 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
"gnu-win32-request@cygnus.com" with one line of text: "help".


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]