Link to home
Start Free TrialLog in
Avatar of ry4096
ry4096

asked on

Difficulty using getkey() in a loop.

Hello.
     I've been tring to make a game with active gameplay in Power C. But I ran into a bug that I'm not sure how to fix: after I press a key, it reads that character over and over. If I press the key for the turret on the tank to go left once, it spins around and never stops. It also stops listening to the keyboard so I have to press ctrl-alt-delete to stop it. This is the format so far:
 char in;
 for(;;)
 {
     in = getkey();
     (if statements regarding what "in" is)
     
     (refresh the screen)
     fflush(stdin);
 }

  Does anyone know how to fix this?
 
ASKER CERTIFIED SOLUTION
Avatar of joachimc
joachimc

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ry4096
ry4096

ASKER

Thanks, but my compiler (Power C, made in 1993 by MIX Software) didn't come with that function. Do you know where I could find its source code and download it?
Or if not, buy it?
Why on earth would you use a compiler from the dark ages ? Download Dev cpp if you want a free compiler. It very good.

Otherwise it's defined in
Header: Declared in Winuser.h; include Windows.h.  Library: Use User32.lib.
Avatar of ry4096

ASKER

I like the compiler I have now because it doesn't need to be run in Windoze. I try to avoid using windows because it's so unstable, but Windows XP is an exception, so I might switch.

 Thanks for giving me the name of the Header file it's in. I'll search for it with Google for a while, but if I can't find it, I'll download Dev cpp. Thanks again for the info. I'll accept your answer once I'm able to use the function.
WHAT!!!! windows XP an exception!!! who told you that.... XP sucks.... win2k is more stable.....
Avatar of Kent Olsen

I've not had any trouble with XP or 2000.  NT, however, sucks bit time.  Still, my linux box has never crashed.  :)


Back to the original subject, are you sure that you want to be calling getkey()?  I'm working from memory here, but I thought that this API returned the last keypress no matter when it was pressed.  That is, if you press "K" then getkey() will return "K" every time it's called until you press something else.


Kdo
Avatar of ry4096

ASKER

I've been tring to figure out how to use Dev C++. It's hard because I've always written things in edit (a prehistoric text editor that comes with DOS). Dev C++ looks like a great compiler, but I'm paranoid of making something by using something that runs off Windows. I'm scard that if I use functions from windows libaries, then their bugs might...infect...the stuff I write. Joachimc's response would probably work, so I'll just accept his answer so people who have the same question as I did will know what to do. But I think i'll stick to Ansi C. I know the answer lies somewhere in Assembly Langauge, and I found a huge PDF file on Assembly Launguage about a year ago that I gave up on. I'll start reading about the keyboard routine, and stuff I'll need to know later, like using speackers and a graphics card. Thanks for the input.

ryan