# DirectInput KeyboardState with variable keys

## Recommended Posts

I'm wondering how I would go about checking whether a key has been pressed that has a variable value (allowing custom input keys). I currently have the input working with hard-coded keys but can't quite figure it out for variable values. I could do a loop checking the state of every key and checking if that is my current input key and then actioning but surely there is a better way to do this? This is my current implementataion:
KeyboardState state = deviceKeyboard.GetCurrentKeyboardState();

//What I am currently doing:
if (state[Key.Up])
{
//Do something...
}

//What I want to do:
if ((state[Key.Up]) || (state[strKeyUp]))
{
//Do something...
}


This is sort of a repost as I posted this earlier as an addition to another semi-related post but I figure that I'm more likely to get a response as a separate thread. Thanks

## Create an account

Register a new account

• ### Forum Statistics

• Total Topics
628290
• Total Posts
2981858

• 11
• 10
• 10
• 11
• 17