Only capture mouse input

Apr 1, 2013 at 5:41 AM
Hello, thanks for the library it's the best I've found for MonoGame. I'm trying to add a floating toolbar to my game that the player can use to select different tools, similar to SimCity or Transport Tycoon.

I've added a screen with a single button on it as a test GUI for my game, but unfortunately the keyboard being captured means I can't use the underlying game controls.

I tried emulating their behaviours by hooking:
_gui.CharEntered += CharEntered;
but the movement is jerky and I can't use more than one keypress at a time (ie pressing up and left at the same time doesn't work)

Any suggestions?
Coordinator
Apr 1, 2013 at 2:25 PM
but unfortunately the keyboard being captured means I can't use the underlying game controls.
I'm not sure what you mean by this. Polling using Keyboard.GetState() should still work. If it doesn't that is an issue that I need to fix.
_gui.CharEntered += CharEntered;
Should be an acceptable way to handle input. If it is slow and jerky it may be that your handler is too heavy. Also you can not use more that one keypress but by using the keyup and keydown events you can record which moment keys are pressed and handle diagonals.
Apr 1, 2013 at 10:34 PM
Edited Apr 1, 2013 at 10:34 PM
Thanks for the reply!

I think the polling method isn't working, if I put this in my screen's Update method, that condition never becomes true, even after disabling the event hooks:
        public override void Update() {
            KeyboardState CurrentKeyBoardState = Keyboard.GetState();
            if (CurrentKeyBoardState.IsKeyDown(Keys.A)) {
                System.Diagnostics.Debug.WriteLine("true");
            }
            _gui.Update();
        }
Coordinator
Apr 2, 2013 at 4:49 AM
bpgarman wrote:
Thanks for the reply!

I think the polling method isn't working, if I put this in my screen's Update method, that condition never becomes true, even after disabling the event hooks:
        public override void Update() {
            KeyboardState CurrentKeyBoardState = Keyboard.GetState();
            if (CurrentKeyBoardState.IsKeyDown(Keys.A)) {
                System.Diagnostics.Debug.WriteLine("true");
            }
            _gui.Update();
        }
Are you using the download version or the latest from the repo? I cleaned up a few issues since the release and everything should be stable, hopefully this is part of the the couple of bugs I caused by not passing on messages properly (which has been fixed in the trunk). I have a couple of tests this week but will look into it over the weekend and add in a test or two to make sure it doesn't happen again.
Apr 2, 2013 at 8:03 AM
Aha! I downloaded the source and built it, now it works perfectly and passes the input all the way down to the main Game class. Thank you!
Coordinator
Apr 2, 2013 at 8:13 PM
bpgarman wrote:
Aha! I downloaded the source and built it, now it works perfectly and passes the input all the way down to the main Game class. Thank you!
I need to clean up my deployment method. Currently I have to rebuild the example project, nuget packages, and build the dlls per each release. But until I make it less tedious thier might often be delays from the source being improved and that being represented by an new version being released.