delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/1997/11/05/19:05:21

From: GBradfor AT fhssmtp DOT redstone DOT army DOT mil (GBradfor)
Subject: Problem with GetKeyState()
5 Nov 1997 19:05:21 -0800 :
Message-ID: <0008EF83.3272.cygnus.gnu-win32@fhssmtp.redstone.army.mil>
To: gnu-win32 AT cygnus DOT com

     What is wrong with the following program?
     
        #include <stdio.h>
        #include <stdarg.h>
        #include <windows.h>
     
        #include "Functions.h"
     
     
        void  main (void)
        {
                short keystate;
     
                printf("\nThe program has started.\n");
     
                while (!(keystate=GetKeyState(0x61)));
                printf("\nAnd the appropriate key has been pressed.\n");
     
                if (0x8 & keystate)
                {
                        printf("\'a\' is pressed.\n");
                }
     
                while (keystate=GetKeyState(0x61));
                printf("\'a\' has been released.\n");
        }
     
     
     It is compiled under bash with
     gcc -o keystate.exe keystate.c -I$GCC_WIN_INCLUDE -luser32 
     
     where GCC_WIN_INCLUDE is an environment variable pointing to the Windows32 
     directory.
     
     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.
     
     Given this, and that 0x61 is ASCII for 'a', I would think that the program 
     would print the opening statement, wait for 'a' to be struck, print the 
     next two statements, wait for 'a' to be released, and print the last 
     statement.
     
     This ain't happening.  The program prints the first statement and hangs.
     
     What am I misunderstanding here?
     
     Thanks for your help and patience.
     
     /s/
     Pat Bradford
     
     Respond to:
        gbradfor AT redstone DOT army DOT mil
                AND/OR
        p_n_brad AT traveller DOT com
-
For help on using this list (especially unsubscribing), send a message to
"gnu-win32-request AT cygnus DOT com" with one line of text: "help".

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019