Quantcast
Channel: Community | MonoGame - Latest topics
Viewing all articles
Browse latest Browse all 6821

Custom key binding, am I on the right track?

$
0
0

@lozzajp wrote:

Wondering if I am on the right track for future proofing input controls so that a user can set custom keys or use a gamepad.

Right now I have two enums:

enum Input
{
    Up,
    Down,
    Action
}

enum InputType
{
    Press,
    Release,
    Hold
}

Then in my main game1.cs update loop I have a call to my function control()

void Control()
{
    cState = pState; // current/previous keyboard state
    cState = Keyboard.GetState();

    Input input;
    InputType type;

    if (cState.IsKeyDown(Keys.W)) // Plan is to change Keys.W somehow later
{
    input = Input.Up;
    type = InputType.Hold;
}

/* Similar functions with pState and cState to determine hold, press or release. */
ScreenManager.Control(input, type); // Passes it through to screen manager and current screen updates/controls

}

So later in my screens I can just make a check for Input.Up && InputType.Press to just for example move a menu item up once.

Does this seem like a good way to go, say I want to change up from W key to Up key or anything else, I only change once in my code?

Could I easily adapt this to a user in a settings menu inputting their own key?

Posts: 3

Participants: 3

Read full topic


Viewing all articles
Browse latest Browse all 6821

Trending Articles