?
Solved

Difficulty using getkey() in a loop.

Posted on 2003-03-02
7
Medium Priority
?
973 Views
Last Modified: 2008-01-09
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?
 
0
Comment
Question by:ry4096
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 4

Accepted Solution

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

Author Comment

by:ry4096
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?
0
 
LVL 4

Expert Comment

by:joachimc
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.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

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

 

Author Comment

by:ry4096
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.
0
 
LVL 1

Expert Comment

by:makkbru
ID: 8087148
WHAT!!!! windows XP an exception!!! who told you that.... XP sucks.... win2k is more stable.....
0
 
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.


Kdo
0
 

Author Comment

by:ry4096
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.

ryan
0

Featured Post

Percona Live Europe 2017 | Sep 25 - 27, 2017

The Percona Live Open Source Database Conference Europe 2017 is the premier event for the diverse and active European open source database community, as well as businesses that develop and use open source database software.

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.
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses

765 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