Disable mouse input and cursor in game

Hello, I’d like to completely disable everything related to mouse input. My game should be controlled only via keyboard (GUI and gameplay).

So, how can I disable mouse input and cursor? I don’t want to show cursor in whole game and as I said game should only use keyboard.

Thanks.

To disable mouse input, open the InputManager from Edit > Project Settings > Input. Remove the input entries with Mouse in their name. Expand Fire1 - Fire3 and remove the mouse buttons from these. To hide the cursor, use the statements:

Cursor.lockState = CursorLockMode.locked;
Cursor.visible = false;

Hey.
I had a similar issue and this worked for me. If there’s any mouse clicks it just goes back to the default selection.

If you stored your current selection in a variable you could always use that as a parameter: CatchMouseClicks(currentButton);

	// Update is called once per frame
	void Update () {

        if (Input.GetMouseButtonDown(0) || Input.GetMouseButtonDown(1) || Input.GetMouseButtonDown(2))
        {

            CatchMouseClicks(defaultSelection);

        }

    }


    public void CatchMouseClicks(GameObject setSelection)
    {

        EventSystem.current.SetSelectedGameObject(setSelection);

    }

If you are using NewInputSystem just don’t add “delta[mouse] or anything related to mouse”

A bit late, but I just found this as I was trying to do the same.

What I did was have a GO (named MouseDisable) with a UI Image on it that stretches across the whole screen, and has ‘Raycast Target’ ticked. Also, make the Color white, and with Alpha = 0. IE not visible.

Then when ever I change the Cursor.visible, I just enable/disable that GO, and it ‘absorbs’ all the mouse clicks.

So, something like:

public void SetCursorVisible(bool vis) {
    Cursor.visible = vis;
    MouseDisable.SetActive(!vis);
}

Worked fine for what I needed. HTHs.

Cursor.lockState =CursorLockMode.locked;
Cursor.visible = false;

it’s worked thx so much!

@$$anonymous$$

1 - Turn your Buttom in a Prefab
2 - Atach this scrip on him

public class ChooseScripName : MonoBehaviour , ISelectHandler
{
public void OnSelect(BaseEventData eventData)
{
EventSystem.current.firstSelectedGameObject = this.gameObject;
}

}

3 - In your UI or where you call the buttoms put these lines inside Update Method

    if (Input.GetMouseButtonDown(0)) 
    {
        EventSystem.current.SetSelectedGameObject(EventSystem.current.firstSelectedGameObject);
    }

This Solved for me. Ever I click, the buttom remains selected.

The StandaloneInputModule is the code that sends mouse events and also converts keyboard events into selected/focused objects into Unity’s Canvas UI system.

You can disable this module which will prevent sending over the mouse and keyboard button events to the canvas.

If you want to disable just the mouse, you can make a new class to override the StandaloneInputModule, Override the ‘process’ function and just do this:

public override void Process()
{
    bool selectedObject = this.SendUpdateEventToSelectedObject();
    if (this.eventSystem.sendNavigationEvents)
    {
        if (!selectedObject)
            selectedObject |= this.SendMoveEventToSelectedObject();
        if (!selectedObject)
            this.SendSubmitEventToSelectedObject();
    }
    //this.ProcessMouseEvent();
}