Jump to content

Why is the camera moving even though I called Event.current.Use() on a KeyDown event?


Recommended Posts

I'm creating a "spinner" control, which displays a number which the user can adjust by clicking the number and pressing the up and down arrow keys. All this is working fine, but when I press an up or down arrow key, not only does that make the number in my control change; it also moves the camera.

This is happening even though I'm calling Event.current.Use() in my event handler for KeyDown events. I thought that calling Event.current.Use() would prevent the camera from moving.

The desired behavior is that if the user presses the up or down arrow key while a spinner has keyboard focus, the spinner's value change and the camera does not move.

Here's the event handler itself:

case EventType.KeyDown:
    if (thisHasKeyboardFocus)
    {
        if (Event.current.keyCode == KeyCode.DownArrow)
        {
            value -= 1;
        }
        else if (Event.current.keyCode == KeyCode.UpArrow)
        {
            value += 1;
        }

        Event.current.Use();
    }
    break;

Here's the entire file defining the spinner control: https://github.com/tswett/WarrigalsAutopilot/blob/a360c575651a30970b2c13f18fe30e88746e0c43/WarrigalsAutopilot/Odospinner.cs

And here's the GitHub issue I created for this problem: https://github.com/tswett/WarrigalsAutopilot/issues/1

Any help would be appreciated!

Link to comment
Share on other sites

2 hours ago, Li0n said:

@Warrigal not sure it can applies to your case but did you look what you can do with the InputLockManager class ? You can use it to prevent a click on a GUI element from passing through it, maybe that can help.

Well, it's the key-down event which I want to consume, not the mouse click event. In any case, are there other mods which use InputLockManager for the purpose of consuming an input event? It would be really helpful to have something else to imitate.

Link to comment
Share on other sites

7 hours ago, Warrigal said:

Well, it's the key-down event which I want to consume, not the mouse click event. In any case, are there other mods which use InputLockManager for the purpose of consuming an input event? It would be really helpful to have something else to imitate.

I've just try and InputLockManager do catch the key-down event.

Quote

InputLockManager.SetControlLock (ControlTypes.CAMERACONTROLS , "SomeName");

...

InputLockManager.RemoveControlLock ("SomeName");

I use it in ModuleMotionDetector.cs (in UpdateGUI()), for CrewLight. I've recompiled this version so you can give it a try, open the motion detector GUI (right-click on a light, motion detector button), when your mouse is hover the GUI the arrow keys don't move the camera anymore.

Link to comment
Share on other sites

This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...