InputManager - access state


31-12-2011 15:20:47

For writing my own input framework which can consume events from MyGUI, methods like getLastPressedPosition(), getMousePosition() & isControlPressed() are very useful.

But, it's frustrating I can't access the current state of mouse buttons and keyboard keys... MyGUI stores this state so having to rewrite this is inefficient.
Is it deliberate this isn't accessible, or did nobody need it before?


01-01-2012 19:53:58

In my project, I inject input events, so Mygui knows whether a key is pressed and so on. I don't think, that changed in during the last versions (> 3.0.1).
And in my opinion Mygui is a pure GUI framework and doesn't know the input of the user (you have to inject the necessary information).

Besides it is not so difficult to get the (mouse button or keyboard) state. Just hook into the windows message queue and catch the messages (= events) at the source. You only need to know the handle of the renderwindow (usually Win32). Or you use OIS...


02-01-2012 13:06:39

Yes you have to inject input into MyGUI so you could cache it yourself at this time. But since MyGUI also caches the state, accessing MyGUI's state would be simpler. It gets a bit messy if you are combining input from the WndProc with MyGUI, and if you are multi-platform then the fact MyGUI is platform-independent makes it even more useful.


02-01-2012 14:01:59

If you want a platform independend InputManager, than use SDL or OIS. These library caches the input and are really plattform independed. If you still want to first inject all input into Mygui and later "get the cached input back", there are two possibilities: Save Input in variables before you inject them into Mygui (recommend) or just edit MyGUI's InputManager: Add some global variables into inputmanager and modify the "inject"-methods to update these variables, but again it's unnecessary if you just cache them by yourself!


02-01-2012 14:14:08

As Tubulii said MyGUI is pure GUI framework, and it is not designed to provide you information about input. Also keep in mind, that this is only GUI related input information and in some cases input is not injected into GUI, when it is handled by other application modules.

And by the way, we do not store complete mouse button state in InputManager - when you inject mouse press and it is not over GUI we do not store any information about pressed mouse button, also only one keyboard key state are store plus few control keys (Shift and Ctrl).


02-01-2012 16:48:19

Thanks for replies. At the moment we don't use SDL/OIS as we need to directly manage the MessageLoop (or non Windows equivalent), and I wanted to minimize libraries used since we need to support iOS as well.
Off-topic slightly, but OIS can be used in the same way right - I can inject events into it from my custom message-loop?


02-01-2012 17:18:31

Do you want to inject custom events into OIS?
I am not sure, instead of injecting (fake) input into OIS, just inject it into YOUR application (usually you have callbacks for the mouse, keyborad events -> just call them directly). Same for MyGUI, just inject fake events, just like OIS would do. In my project I injected fake input into MyGUI to implement custom cursor behaviour (loop and jump over UI controls) by injecting abs coordinates twice.
Or you modify OIS source.


02-01-2012 17:28:54

Do you want to inject custom events into OIS?What I mean is, I don't (maybe) want to let OIS handle all the input to my application... I might need to have my own custom message handler.

What I was asking was instead of letting OIS capture mouse/keyboard events, can I catch them in my WndProc and manually inject them into OIS? Then OIS would work as normal, but I'd have direct control over it.


02-01-2012 17:36:28

I just realised it might not be clear why I am so interested in MyGUI's input state... normally we let MyGUI handle input and call handlers when a button is clicked, etc.

In my case, I use Canvas/ImageBox to wrap an Ogre RenderTarget/Viewport, so I am using MyGUI event handling to notify when user clicks on the viewport... normally you would probably do that directly through OIS/Win32.


02-01-2012 17:41:28

Ok,I understand,

but I am afraid, I cannot help you, except modify OIS source and change the way Mouse and Keyboard get there input, I have no idea. You should ask in the Ogre forum.

EDIT: There is a MyGUI sample for ImageBox -> Viewport, in which the mesh can be rotated by the mouse. But still I have no idea. Sorry.. :(


02-01-2012 17:45:02

That's fine, thanks for the replies :) I will look in OIS/Ogre forums for more information.