GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 18-Jun-2004, 00:27
Kilgayne's Avatar
Kilgayne Kilgayne is offline
Junior Member
 
Join Date: Jun 2004
Location: somewhere
Posts: 52
Kilgayne is on a distinguished road
Unhappy

keyboard events in turbo c++


k i was trying to make a lil game in c++, everything seemed alright 'til i realized one major thing was missing : the keyboard input (omg). obviously the getch() and cin >> functions won't do i need a function that will return if a key is pressed and what it is. or sumthing like that. anyway i need something that will return the curent active key without pausing the game like getch() do. that's it, i need a getch() that won't pause the app...

is there anything in the basic header files of borland turbo c++ 3.idunno that could solve my prob? or if you could give me one with the function i need in it i would appreciate it as well.

...

btw, nice forum!
  #2  
Old 18-Jun-2004, 01:06
aaroncohn's Avatar
aaroncohn aaroncohn is offline
Regular Member
 
Join Date: Feb 2004
Location: Bay Area, CA.
Posts: 564
aaroncohn is a jewel in the roughaaroncohn is a jewel in the roughaaroncohn is a jewel in the rough
Spelling the word "something" with an 'o' instead of with a 'u' may not help you solve your input problem, but at least I'd be thinking about your situation instead of commenting on your massacre of the word "something."
__________________
-Aaron
  #3  
Old 18-Jun-2004, 07:46
machinated machinated is offline
Regular Member
 
Join Date: Mar 2004
Location: victoria, canada
Posts: 324
machinated has a spectacular aura aboutmachinated has a spectacular aura about
kbhit() returns true if a key gets hit. i think it's in conio.h
__________________
spasms!!!
  #4  
Old 18-Jun-2004, 10:07
mithunjacob's Avatar
mithunjacob mithunjacob is offline
Junior Member
 
Join Date: Jun 2004
Location: Vellore, India
Posts: 65
mithunjacob will become famous soon enough
Arrow

Quote:
Originally Posted by machinated
kbhit() returns true if a key gets hit. i think it's in conio.h
Yeah, kbhit()'s your answer..it can be used like this

Code:
while(!kbhit()) switch(getch()) { case '2': GoUP(); break; case '4': GoLT(); break; case '6': GoRT(); break; case '8': GoDN(); break; case 27: Quit(); }

This will force the programme into a continous loop until a key is encountered..modify it as per your own programme..it doesn't need to be a loop, you can have if(kbhit()) { switch(..... which will check, every time it encounters the if statement..
  #5  
Old 18-Jun-2004, 16:03
Kilgayne's Avatar
Kilgayne Kilgayne is offline
Junior Member
 
Join Date: Jun 2004
Location: somewhere
Posts: 52
Kilgayne is on a distinguished road
\o/ hey thanks guys, i've been searching it for months now!

...

i didnt know twas in conio... silly me.
  #6  
Old 19-Jun-2004, 20:38
Kilgayne's Avatar
Kilgayne Kilgayne is offline
Junior Member
 
Join Date: Jun 2004
Location: somewhere
Posts: 52
Kilgayne is on a distinguished road
erm... just one last thing about the input thingy...

i want my game to have like a fps rate so i use the "delay" function to reduce the speed of my app.. it works just fine when i don't hold a key down, but if i do, it starts beep-ing and the program freezes. it's not very convenient when we play a platform game. if i don't put that delay function in my prog., it wont beep and everything will be a-ok... but it won't run at the same speed on others pcs...

what can i do about it?
  #7  
Old 19-Jun-2004, 22:45
aaroncohn's Avatar
aaroncohn aaroncohn is offline
Regular Member
 
Join Date: Feb 2004
Location: Bay Area, CA.
Posts: 564
aaroncohn is a jewel in the roughaaroncohn is a jewel in the roughaaroncohn is a jewel in the rough
Hmm... I am not sure what reducing the speed of your app accomplishes... but generally, you'd want it to run at its optimal speed. Can't you ask the video card what the fps rate is? I don't know anything about graphics programming yet. You should teach me
__________________
-Aaron
  #8  
Old 20-Jun-2004, 02:12
WaltP's Avatar
WaltP WaltP is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Midwest US
Posts: 3,243
WaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to all
Quote:
Originally Posted by Kilgayne
erm... just one last thing about the input thingy...

i want my game to have like a fps rate so i use the "delay" function to reduce the speed of my app.. it works just fine when i don't hold a key down, but if i do, it starts beep-ing and the program freezes. it's not very convenient when we play a platform game. if i don't put that delay function in my prog., it wont beep and everything will be a-ok... but it won't run at the same speed on others pcs...

what can i do about it?
Don't put the delay in by a command that pauses the game, but by computing the delay. A simple example:
CPP / C++ / C Code:
timeval = time() + 2;      // Wait for 2 seconds before proceeding
while (ch != EXIT_KEY)
{
    if (kbhit())
    {
        // process all keystrokes
    }
    if (time() > timeval)   // check if we should process
    {
        timeval = time() + 2;   // reset the pause value
         // process your game
    }
     else
    {
        // Not ready to process the game, just continue
    }
}
__________________

Age is unimportant -- except in cheese
  #9  
Old 23-Jun-2004, 13:46
Kilgayne's Avatar
Kilgayne Kilgayne is offline
Junior Member
 
Join Date: Jun 2004
Location: somewhere
Posts: 52
Kilgayne is on a distinguished road

CPP / C++ / C Code:
if ((clock/TCK_CLK)>=(befclk+0.025))
{
    //fps=approx. 30-40
}

well i guess my problem is solved
 
 

Recent GIDBlogToyota - 2008 September Promotion by Nihal

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Win32 API Keyboard events JBowe MS Visual C++ / MFC Forum 4 04-Mar-2004 11:03
list of the most common keyboard and mouse shortcuts for IE, Opera and Firebird jrobbio Computer Software Forum - Windows 2 04-Sep-2003 09:10

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 11:27.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.