Sign in to follow this  
nsto119

A system for handling complex input actions I've been toying with...

Recommended Posts

I've been playing around with this idea in my head for a while, I'm getting ready to start work on it so I'm looking for some opinions. Anyway, the problem I am faced with is GUI mouse and keyboard input. Key down/up events and the like are easy, since nearly any input system provides those for you. But, key press events aren't the only kind you look for with a GUI, you also need to track mouse dragging, making sure the mouse hasn't moved off a button between button press and release, etc. The problem with this is that it can get incredibly messy, trying to track each and every different possible complex input event, especially since some of them need pre-existing special conditions before they should even be tracked. So, my idea is this: I have a "InputEvent" base class. This class will represent all the different actions I would want to watch for. I'd mantain a list of this class in some kind of Input manager class. Each frame, the input manager would check for... input. So, say for example a mouse button is clicked. Lots of different input events can come from a mouse press - a drag and mouse button release, for example. So, the input manager would then add a DragEvent and ReleaseEvent object (which both derive from InputEvent) to the list of events. Each frame, the list of events would be iterated through once and an Update method would check for input device conditions that either satisfy or cancel the event that the InputEvent is looking for - for example, if a DragEvent was in the list, each frame it would check to make sure the mouse hasn't been released - if it has, the user would no longer be dragging the mouse and the DragEvent would be removed from the list. I'm sure it probably sounds way more confusing in the post than it does in my head, but hopefully I've explained it well enough. I've just been looking for a solution to the messy input tracking system I have now, and this seemed like a decent idea.

Share this post


Link to post
Share on other sites
A pretty good idea, I must say. It would be better combined with a factory approach: a factory object is triggered by simple events, such as mouse button press, then generates a drag object event and a click object event to handle the various possiblities.

Share this post


Link to post
Share on other sites
A factory approach is a good idea, I was kind of struggling with how I was going to deal with creating the events, because even that could get kind of messy, but a factory seems like a good, clean approach. Thanks a bunch.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this