I'm using the KeyboardState state way (if there are any others) of handling key presses for a PC game. It has been working fine for single key presses but now I am trying to handle multiple key presses at once.
I have it grab the newState at the top and then save it to the oldState at the bottom. I've tried it this way:
if (newState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.D2) && newState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.LeftAlt))
{
if (equipment_accessory2 != null)
UseItem(equipment_accessory2, "Accessory 2");
}
And I've also tried:
Microsoft.Xna.Framework.Input.Keys[] currentPressedKeys = newState.GetPressedKeys();
bool altPressed = false, twoPressed = false;
for (int i = 0; i < currentPressedKeys.Length; i++)
{
if (currentPressedKeys[i] == Microsoft.Xna.Framework.Input.Keys.LeftAlt)
altPressed = true;
else if (currentPressedKeys[i] == Microsoft.Xna.Framework.Input.Keys.D2)
twoPressed = true;
}
...
if (altPressed)
{
if (equipment_accessory2 != null && twoPressed)
UseItem(equipment_accessory2, "Accessory 2");
}
Both ways work to a certain degree. The end result is that you're able to press alt and then a key between 1 and 5 to quick use a consumable. Normally you have skills in those slots so holding down alt makes the skills you have bound disappear and instead shows your quick use items.
The problem I'm having is that no matter what I have tried, the only way it works is that you have to hold 2 then hold alt. If you hold alt first and press/hold 2 it does nothing and doesn't work. I have spent 4 or 5 hours trying to figure out why it only works when you hold down 2 and then press alt. The problem with having it only work this way is if they have a skill bound to 2 then they're going to use the skill so the system is supposed to be to hold down left alt to swap the skill bar to the quick use bar.
I can't figure out why both ways I've tried doing multi key input aren't working when I press alt first.
EDIT: ok it must be something with my keyboard because alt+1 works but 2, 3, 4, and 5 don't work. EDIT2: restarted and 2-5 work now too, was something with my keyboard apparently.