InputManager - access state
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?
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...
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.
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!
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).
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?
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.
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.
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.
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..
That's fine, thanks for the replies
I will look in OIS/Ogre forums for more information.