Click here to Skip to main content
15,888,286 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am wanting to detect if any key is being pressed but as far as I can tell the if statement isn't being triggered.

"working" is being printed so GameLoop() is being called.

Not sure what to do.. Thanks for the help!

What I have tried:

public static int GameLoop()
           {
               while(true)
               {
                   if(Console.KeyAvailable == true)
                   {
                       Environment.Exit(0); //test to see if being used
                       Player.KeyPressed = Console.ReadKey().KeyChar;
                       Player.Movement();
                   }

                   Console.WriteLine("working");
Posted
Updated 1-Nov-17 3:37am

Probably, it's the WriteLine that is causing the problem: that will be done so often that the output-to-the-console part is so busy it's backed up to high heaven.

Instead of outputting all the time, use DateTime.Now to detect when the number of seconds has changed, and output one line per second instead. I suspect that KeyAvailable will magically start to work...
 
Share this answer
 
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900