C Board  

Go Back   C Board > General Programming Boards > Game Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 09-24-2001, 05:03 AM   #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...
adamdalziel is offline   Reply With Quote
Old 09-24-2001, 05:23 AM   #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?
__________________
www.EberKain.com
Eber Kain is offline   Reply With Quote
Old 09-24-2001, 08:13 AM   #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!!!
adamdalziel is offline   Reply With Quote
Old 09-24-2001, 08:41 AM   #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
Stoned_Coder is offline   Reply With Quote
Old 09-24-2001, 09:32 AM   #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!!
adamdalziel is offline   Reply With Quote
Old 09-24-2001, 11:49 AM   #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.
no-one is offline   Reply With Quote
Old 09-24-2001, 04:20 PM   #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.
adamdalziel is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
can someone help me with these errors please code included geekrockergal C Programming 7 02-10-2009 02:20 PM
About aes gumit C Programming 13 10-24-2006 03:42 PM
Trouble with a lab michael- C Programming 18 12-06-2005 11:28 PM
Linux: Send keyboard input to background process xErath Tech Board 2 12-09-2004 07:02 PM
Need help with keyboard input wiramu C++ Programming 2 11-28-2003 02:44 PM


All times are GMT -6. The time now is 05:22 PM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2

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