Results 1 to 6 of 6

Thread: Search if Key is pressed [RESOLVED]

  1. #1

    Thread Starter
    Fanatic Member sql_lall's Avatar
    Join Date
    Jul 2002
    Location
    Up Above (i.e. AUS)
    Posts
    571

    Talking Search if Key is pressed [RESOLVED]

    Hi!
    I was trying to make an interactive program, and wanted to put this in it:
    Code:
    do stuff...
    if(left button is pressed)
    {
     change a certain value
    }
    keep doing stuff
    Of course, this is only pseudo-code.
    I know about cin>> but the problem is i don't want the program to stop when i check for input.
    any ideas?? Thanks
    Last edited by sql_lall; Jun 21st, 2003 at 05:33 AM.
    sql_lall

  2. #2
    Frenzied Member
    Join Date
    Jul 2002
    Posts
    1,370
    Use the GetAsyncKeyState() api, the virtual keycode is the only argument. It returns>0 if the key has been pressed at any time since you last called GetAsyncKeyState.

    You can put the call to GetAsyncKeyState in a function that you access via SetTimer, or inside the code block that reads the keyboard.

    Since people can't push keys faster than 6-8 times per second a timer with a wait of 120ms is adequate. The automatic repeat on keys is usually 6 keys/sec

  3. #3
    Frenzied Member
    Join Date
    Jul 1999
    Posts
    1,800
    just note I experienced compatablitity problems with this and windows 98....works perfectly in XP though

  4. #4
    PowerPoster sunburnt's Avatar
    Join Date
    Feb 2001
    Location
    Boulder, Colorado
    Posts
    1,403
    Also the GetAsyncKeyState() doesn't care if your application had input focus when the key was pressed or not.
    Every passing hour brings the Solar System forty-three thousand miles closer to Globular Cluster M13 in Hercules -- and still there are some misfits who insist that there is no such thing as progress.

  5. #5

    Thread Starter
    Fanatic Member sql_lall's Avatar
    Join Date
    Jul 2002
    Location
    Up Above (i.e. AUS)
    Posts
    571

    Talking Thanks

    Thanks for the help.
    Just wondering what kind of things i must #include at the start to be able to use it.
    sql_lall

  6. #6
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    <windows.h>

    Notw also that it is non-portable.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width