Keyboard input error when pressing 3 keys

I have a problem in my code where 3 keys are pressed at the same time. When I click

  • Up + Right + Space: moves and the object shoots
  • Up + Left + Space: moves but doesn't fire
  • Down + Right + Space: Moves, but doesn't fire
  • Down + Left + Space: Moves, but doesn't fire
  • All other key combinations are fine.

here is my code:

if (newkbState.IsKeyDown(Keys.Up))
    player.MoveFwd();
else if (newkbState.IsKeyDown(Keys.Down))
    player.MoveBkwd();
else
    player.StopMoving();

if (newkbState.IsKeyDown(Keys.Left))
    player.TurnLeft();
else if (newkbState.IsKeyDown(Keys.Right))
    player.TurnRight();
else
    player.StopTurning();

if (newkbState.IsKeyDown(Keys.Space))
    player.Fire();

      

+3


source to share


2 answers


Rather the main problem - but does the keyboard support more than three keys at a time? "Ghost", as it is called, is not unheard of in older keyboards:

https://www.microsoft.com/appliedsciences/antighostingexplained.mspx



Are you 100% sure about your code?

+7


source


This could be a problem with your keyboard (some Microsoft keyboards, for example, have similar problems); just to be safe try a different keyboard.



0


source







All Articles