Jump to content

  • Log In with Google      Sign In   
  • Create Account


#ActualBUnzaga

Posted 06 October 2012 - 05:45 AM

I am trying to put together a thorough input system, and I can't seem to work it through in my head (or in code).

Say for example, I want to use x number of keys, or mouse button(s) or joystick button(s) to perform a single continuous action, for example 'running forward'.

I can handle gathering the input, and I can handle associating the event with an action, but what I can't figure out, is the best way to cross-check for the current state of the 'other' inputs.

For discussion sake, lets say a key event would be something like... 'key_space', 'mouse_1', 'joy_1', followed by the appropriate data, such as 'true', 'false', .0121, etc.

So say I bound 'key_w', 'key_up', as well as 'mouse_2' to the action 'forward'.

So now if I press either of those keys, or the right mouse button, the 'forward' action will happen, meaning, the player will run 'forward'.

So now say I press all three, this works fine, because they all do the same function. But what happens when I let go of the right mouse button? In code, it would send through a 'mouse_2' event with the data 'false', which should cause the player to stop moving forward, unfortunately, both key_w, and key_up, are still down...

Is there any way to tackle something like this? Where I could have (n) number of inputs to handle a single thing like this? I know if I have a finite number of options, I could just check for the state of the keys when the 'up' event occurs... if(false == keys_w){/*stop*/}else{/*keep going*/}

I thought of using an integer for this, but that just seems sloppy... Like if I press key_w, held_amt++, if I press key_up, held_amt++, if I press mouse_2, held_amt++. Then when I release one of them, I do held_amt--, check if it is equal to zero, and then if it is, stop running...

I don't know, this just seems very sloppy to me.

On top of this, say I pressed forward, then back, then a different forward key. I would want it to respond properly to the currently held down keys, all of which could be reassigned and the amounts of them could be 1 to n.

Please help if you can! Posted Image

By the way, I have already read through http://www.gamedev.n...stem-for-games/ which was informative and helpful, but it doesn't cover my issue. I have also tried looking up anything I can find in google, as well as on these boards, but most of them have to do with the lower level logic of how to just get multiple sources of input, rather than the higher functionality of how to orchestrate it.

EDIT: The only other method I was thinking of was polling the state of each potential input onUpdate, but I wanted use a callback system instead, onKeyChange... onKeyUp / onKeyDown type of thing.

#2BUnzaga

Posted 06 October 2012 - 05:43 AM

I am trying to put together a thorough input system, and I can't seem to work it through in my head (or in code).

Say for example, I want to use x number of keys, or mouse button(s) or joystick button(s) to perform a single continuous action, for example 'running forward'.

I can handle gathering the input, and I can handle associating the event with an action, but what I can't figure out, is the best way to cross-check for the current state of the 'other' inputs.

For discussion sake, lets say a key event would be something like... 'key_space', 'mouse_1', 'joy_1', followed by the appropriate data, such as 'true', 'false', .0121, etc.

So say I bound 'key_w', 'key_up', as well as 'mouse_2' to the action 'forward'.

So now if I press either of those keys, or the right mouse button, the 'forward' action will happen, meaning, the player will run 'forward'.

So now say I press all three, this works fine, because they all do the same function. But what happens when I let go of the right mouse button? In code, it would send through a 'mouse_2' event with the data 'false', which should cause the player to stop moving forward, unfortunately, both key_w, and key_up, are still down...

Is there any way to tackle something like this? Where I could have (n) number of inputs to handle a single thing like this? I know if I have a finite number of options, I could just check for the state of the keys when the 'up' event occurs... if(false == keys_w){/*stop*/}else{/*keep going*/}

I thought of using an integer for this, but that just seems sloppy... Like if I press key_w, held_amt++, if I press key_up, held_amt++, if I press mouse_2, held_amt++. Then when I release one of them, I do held_amt--, check if it is equal to zero, and then if it is, stop running...

I don't know, this just seems very sloppy to me.

On top of this, say I pressed forward, then back, then a different forward key. I would want it to respond properly to the currently held down keys, all of which could be reassigned and the amounts of them could be 1 to n.

Please help if you can! Posted Image

By the way, I have already read through http://www.gamedev.n...stem-for-games/ which was informative and helpful, but it doesn't cover my issue. I have also tried looking up anything I can find in google, as well as on these boards, but most of them have to do with the lower level logic of how to just get multiple sources of input, rather than the higher functionality of how to orchestrate it.

EDIT: The only other method I was thinking of was polling the state of each potential input onUpdate, but I wanted use a callback system instead, onKeyChange... onKeyUp / onKeyDown type of thing.

#1BUnzaga

Posted 06 October 2012 - 05:37 AM

I am trying to put together a thorough input system, and I can't seem to work it through in my head (or in code).

Say for example, I want to use x number of keys, or mouse button(s) or joystick button(s) to perform a single continuous action, for example 'running forward'.

I can handle gathering the input, and I can handle associating the event with an action, but what I can't figure out, is the best way to cross-check for the current state of the 'other' inputs.

For discussion sake, lets say a key event would be something like... 'key_space', 'mouse_1', 'joy_1', followed by the appropriate data, such as 'true', 'false', .0121, etc.

So say I bound 'key_w', 'key_up', as well as 'mouse_2' to the action 'forward'.

So now if I press either of those keys, or the right mouse button, the 'forward' action will happen, meaning, the player will run 'forward'.

So now say I press all three, this works fine, because they all do the same function. But what happens when I let go of the right mouse button? In code, it would send through a 'mouse_2' event with the data 'false', which should cause the player to stop moving forward, unfortunately, both key_w, and key_up, are still down...

Is there any way to tackle something like this? Where I could have (n) number of inputs to handle a single thing like this? I know if I have a finite number of options, I could just check for the state of the keys when the 'up' event occurs... if(false == keys_w){/*stop*/}else{/*keep going*/}

I thought of using an integer for this, but that just seems sloppy... Like if I press key_w, held_amt++, if I press key_up, held_amt++, if I press mouse_2, held_amt++. Then when I release one of them, I do held_amt--, check if it is equal to zero, and then if it is, stop running...

I don't know, this just seems very sloppy to me.

On top of this, say I pressed forward, then back, then a different forward key. I would want it to respond properly to the currently held down keys, all of which could be reassigned and the amounts of them could be 1 to n.

Please help if you can! :D

By the way, I have already read through http://www.gamedev.net/blog/355/entry-2250186-designing-a-robust-input-handling-system-for-games/ which was informative and helpful, but it doesn't cover my issue. I have also tried looking up anything I can find in google, as well as on these boards, but most of them have to do with the lower level logic of how to just get multiple sources of input, rather than the higher functionality of how to orchestrate it.

PARTNERS