0

I am using xna.framework and there is a problem whit this

while (true)
        {
            if (Keyboard.GetState().IsKeyDown(Keys.A))
            {
                Console.WriteLine("Something");
            }
        }

the if statement returns false whatever i do. I've seen another posts here about this problem, but there is no answer that helps me. Any ideas ?

  • http://stackoverflow.com/questions/20804234/c-sharp-check-if-specific-key-is-pressed – Orel Eraki Jul 02 '15 at 21:27
  • You should not use XNA do get the input in a console window. There are native functions to do that (see the link posted above). If you want to try out the basics of xna, use the blank template instead, because it comes with an update function so you don't have to do stuff like while(true). I am not sure, but I guess that would already solve your problem – jalgames Jul 27 '15 at 09:29

1 Answers1

0

You do not need to include the GetState() method, also when getting the keycode for the A key you use keys rather than just key. Your new code would just be

while (true)
{
     if (Keyboard.IsKeyDown(Key.A))
     {
           Console.WriteLine("Something");
     }
}
Will Fisher
  • 413
  • 5
  • 18