Difficulty using getkey() in a loop.

Posted on 2003-03-02
Medium Priority
Last Modified: 2008-01-09
     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;
     in = getkey();
     (if statements regarding what "in" is)
     (refresh the screen)

  Does anyone know how to fix this?
Question by:ry4096

Accepted Solution

joachimc earned 150 total points
ID: 8056648
You could use GetAsyncKeystate(VK_YOURKEY) this would probably fix the problem.

Author Comment

ID: 8061163
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?

Expert Comment

ID: 8062822
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.

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.


Author Comment

ID: 8068770
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.

Expert Comment

ID: 8087148
WHAT!!!! windows XP an exception!!! who told you that.... XP sucks.... win2k is more stable.....
LVL 46

Expert Comment

by:Kent Olsen
ID: 8096013

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.


Author Comment

ID: 8096857
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.


Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

As game developers, we quickly learn that Artificial Intelligence (AI) doesn’t need to be so tough.  To reference Space Ghost: “Moltar, I have a giant brain that is able to reduce any complex machine into a simple yes or no answer. (http://www.youtu…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Integration Management Part 2
Enter Foreign and Special Characters Enter characters you can't find on a keyboard using its ASCII code ... and learn how to make a handy reference for yourself using Excel ~ Use these codes in any Windows application! ... whether it is a Micr…
Suggested Courses

569 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question