Thread: Detecting key down && press

  1. #1
    Registered User
    Join Date
    Mar 2004
    Posts
    180

    Detecting key down && press

    I looked in the help files for Borland C++ builder 6, but they didn't really help! ;(

    I want to dected if:

    key press:
    <statement>
    key down:
    <statement>


    and I need to know what key was pressed down

    thx for the help!

  2. #2
    Registered User
    Join Date
    Aug 2003
    Posts
    1,218
    I think this is compiler and/or OS specific so post your compiler and OS.

  3. #3
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    >>I think this is compiler and/or OS specific so post your compiler and OS.
    He already said he was using Borland, so he must be using a flavour of Windows.
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

  4. #4
    Registered User
    Join Date
    Aug 2003
    Posts
    1,218
    Ooops thats what you get for trying to answer somebody when your tired lol.

  5. #5
    Registered User
    Join Date
    Mar 2004
    Posts
    180
    Borland C++ builder 6.0
    Windows XP

    Code:
     if (GetAsyncKeyState(VK_CODE)==VK_LEFT )
     {
     move_ship_left(User_Ship, Ship_sprite);
     }
     else if (GetAsyncKeyState(VK_CODE)==VK_RIGHT )
     {
     move_ship_right(User_Ship, Ship_sprite);
     }
    this is what i'm doing know, but It doesn't want to work

  6. #6
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    It's not working because you're using GetAsyncKeyState( ) improperly. You may want to have a look at the MSDN article on it.
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

  7. #7
    Registered User
    Join Date
    Mar 2004
    Posts
    180
    Code:
     if (GetAsyncKeyState(VK_LEFT ))
     {
     move_ship_left(User_Ship, Ship_sprite);
     }
     else if (GetAsyncKeyState(VK_RIGHT ))
     {
     move_ship_right(User_Ship, Ship_sprite);
     }
    is this better?

  8. #8
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    That should work.
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 16
    Last Post: 11-23-2007, 01:48 PM
  2. Virtual keys
    By Arkanos in forum Windows Programming
    Replies: 4
    Last Post: 12-12-2005, 10:00 AM
  3. Directional Keys - Useing in Console
    By RoD in forum C++ Programming
    Replies: 38
    Last Post: 10-06-2002, 04:42 PM
  4. FAQ: Directional Keys - Useing in Console
    By RoD in forum FAQ Board
    Replies: 38
    Last Post: 10-06-2002, 04:42 PM