Thread: GetAsyncKeyState - if or while?

  1. #1
    Registered User johnnyd's Avatar
    Join Date
    Mar 2002
    Posts
    70

    Lightbulb GetAsyncKeyState - if or while?

    Hey fellas, I just found out that this nifty little command would help me capture the ALT key in my program. Question is, how exactly do I use this command to capture the key?

    Lemme know if this makes sense:

    if (GetAsyncKeyState(VK_ALT))
    //do whatever

    Because, I'm thinking that I will have to setup a loop to actually catch the ALT keypress. Won't I? I mean it's not like getch() that will wait on the user to enter something. Something to the effect of:

    while (GetAsyncKeyState(VK_ALT))
    //do whatever

    Won't I? Or am I just typing nonsense here?

    MSDN doesn't show me any examples of it's usage in C. Thanks in advance.
    Excuse me, while I water my money tree.

  2. #2
    Has a Masters in B.S.
    Join Date
    Aug 2001
    Posts
    2,263
    well whenever you test for input? test for alt of in the main program loop somewhere with the if form?
    ADVISORY: This users posts are rated CP-MA, for Mature Audiences only.

  3. #3
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,793
    If you have windows proggie then capure WM_KEYDOWN and look for the proper Virtual code (I think its VK_MENU...but i may be wrong)...

    If you have a console then the way I prefer to do it is to setup a seperate thread to read the keyboard using ReadConsoleInput().....

  4. #4
    Registered User johnnyd's Avatar
    Join Date
    Mar 2002
    Posts
    70

    You're right about the VK...

    I did know about the VK_MENU. You're quite right.

    My mind slipped me when I wrote VK_ALT, nonsense I tell you.

    I'm going to attempt the ReadConsoleInput. Is that also in Windows.h?
    Excuse me, while I water my money tree.

  5. #5
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,793

    Re: You're right about the VK...

    Originally posted by johnnyd

    I'm going to attempt the ReadConsoleInput. Is that also in Windows.h?
    Yup its a standard Windows function.......

  6. #6
    Registered User johnnyd's Avatar
    Join Date
    Mar 2002
    Posts
    70

    GetKeyState(VK_MENU & 0x8000) ?

    I've seen some peeps use GetKeyState(VK_MENU & 0x8000) in their C code. What's the significance of the & 0x8000?
    Excuse me, while I water my money tree.

  7. #7
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >What's the significance of the & 0x8000?
    That determines if the most signifigant bit is set.

    -Prelude
    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. GetAsyncKeyState.
    By kevinawad in forum Windows Programming
    Replies: 9
    Last Post: 11-09-2008, 05:02 PM
  2. GetAsyncKeyState Problem
    By kevinawad in forum C++ Programming
    Replies: 1
    Last Post: 11-07-2008, 06:00 PM
  3. Problems with cin and GetAsyncKeyState
    By KgNe in forum C++ Programming
    Replies: 32
    Last Post: 08-21-2008, 10:00 AM
  4. Infinite Loop with GetAsyncKeyState
    By guitarist809 in forum Windows Programming
    Replies: 1
    Last Post: 04-18-2008, 12:09 PM