Keyboard input without waiting (Borland C++)

This is a discussion on Keyboard input without waiting (Borland C++) within the Game Programming forums, part of the General Programming Boards category; I am currently writing a game demo in Borland C++, as I wish to become a games programmer in the ...

  1. #1
    Registered User
    Join Date
    Sep 2001
    Posts
    13

    Talking Keyboard input without waiting (Borland C++)

    I am currently writing a game demo in Borland C++, as I wish to become a games programmer in the near future. The demo is going to be a space battle simulation where you rotate and thrust in 3D space, with the aim of detroying the enemy ship, b4 the opposite occurs!!! My question is this:

    "How does C++ detect the keyboard input at a precise moment, without waitng for a key to be pressed - ie. returning a value of 0 (or likewise) if no key is being pressed at that instant??"

    The getch function is absolotely hopeless as it waits for a keypress (not much good for games)!!

    Can anyone help?

    Thanx, Ad...

  2. #2
    Registered User
    Join Date
    Aug 2001
    Posts
    411
    I use WndProc and windows messages for my user interface stuff, What graphics API are you useing?

  3. #3
    Registered User
    Join Date
    Sep 2001
    Posts
    13
    You'll have to forgive me, am a bit new to C++, although am v familiar with programming - think I'm using OWL API.

    What does API stand for - does it allow me to utilise the keyboard in the way I want?

    I'm confused!!!

  4. #4
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    If you are writing for windows then check out this api function at msdn or in your helpfiles....

    GetAsyncKeyState()
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  5. #5
    Registered User
    Join Date
    Sep 2001
    Posts
    13
    Thanx, think that's exactly what I'm looking for. Am using Borland 5.02 and it's in the Windows API. How do you actually use the function, is it just a case of:

    #include <relevantHeader.h>

    if (GetAsyncKeyState()==codeForRequiredKey)
    statementBlock

    or am I naive to think it could be quite that straight-forward?!!

    Cheers, Ad.

    PS: keep smoking!!

  6. #6
    Has a Masters in B.S.
    Join Date
    Aug 2001
    Posts
    2,267
    more like this

    if(GetAsyncKeyState("W"))
    //do whatever

    also use VK_*? keys for things such as Shift and ctrl

    thre might be something othere than VK_* in borland so your gonna have to look it up in the docs...
    ADVISORY: This users posts are rated CP-MA, for Mature Audiences only.

  7. #7
    Registered User
    Join Date
    Sep 2001
    Posts
    13
    Excellent, that seems to be working a treat now (finally realised that you've gotta include windows.h - duh!!)

    So, have now got thrust & rotation working, so that the position and velocity vectors alter accordingly as you move through 3-Space. Hehe.

    One curious thing happens, though. On compilation, the keys work fine, but if you click in the programme window, they cease to work - anyone know what this could be?

    Cheers for the help. Ad.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. can someone help me with these errors please code included
    By geekrockergal in forum C Programming
    Replies: 7
    Last Post: 02-10-2009, 01:20 PM
  2. About aes
    By gumit in forum C Programming
    Replies: 13
    Last Post: 10-24-2006, 03:42 PM
  3. Trouble with a lab
    By michael- in forum C Programming
    Replies: 18
    Last Post: 12-06-2005, 10:28 PM
  4. Linux: Send keyboard input to background process
    By xErath in forum Tech Board
    Replies: 2
    Last Post: 12-09-2004, 06:02 PM
  5. Need help with keyboard input
    By wiramu in forum C++ Programming
    Replies: 2
    Last Post: 11-28-2003, 01:44 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21