The XNA Keys struct is not marked with the Flags Attribute which means that it's not legal to | a load of keys together like that.
Keys keyCombo = Keys.Left | Keys.A;
Console.WriteLine(keyCombo);
Will print NumPad5, which is clearly not what you want here! You've never been able to do this in any version of XNA, I think the book is just wrong here :O
Copying from one of my own games, this is how I solved it:
#if WINDOWS
public static bool Any(this KeyboardState state, params Keys[] keys)
{
return keys.Any(state.IsKeyDown);
}
#endif
And then you can just do:
KeyboardState k = Keyboard.GetState();
if (k.Any(Keys.Left, Keys.A))
DoStuff();
However, as someone in the comments pointed out this method is bad practice on the xbox due to it allocating (params array allocation, and LINQ allocating an Enumerator). An alternative system for xbox is this:
Keys[] doStuffKeys; //Allocate an array of keys for this particular action
Initialize()
{
doStuffKeyBinding = new[] { Keys.Left, Keys.A };
}
Update()
{
KeyboardState k = Keyboard.GetState();
if (k.Any(doStuffKeys)) //No allocations here!
DoStuff();
}
The Any method needs modifying too:
#if XBOX
public static bool Any(this KeyboardState state, Keys[] keys)
{
for (int i = 0; i < keys.Length; i++)
if (state.IsKeyDown(keys[i]))
return true;
return false;
}
#endif
It's a while since I've done any work for the xbox, but this now shouldn't allocate.
IsKeyUp
alternative. By "it doesn't work" I meant that I can't ever get it to be true - it doesn't matter if both keys are up, one key is down, or both keys is down. In one of those cases it should be true, but none of them were. \$\endgroup\$