Blocking Input
An interface to granularly block mouse input or certain keys.
You may find that you need granular control over blocking the users mouse or keyboard.
In this guide we’ll walk through implementing interacting with an in-game window via a particular key or mouse button, for example, the middle mouse click. You’ll want to follow this pattern if:
- You want a window that is not interactive by default
- You want the user to be able to opt-in to interacting with the window
Simple Approach
The easiest way to accomplish this is with the below code snippet.
Scope
The problem that the scope
method solves is the following:
Imagine you have two windows that have opt-in interactivity. If you use the advanced API mentioned below to try and handle the blocking yourself:
- The user opens Window A
- The user clicks middle mouse to interact with Window A
- The user opens Window B, with Window A still open
- The user closes Window A
- Window A removes cursor blocking that it previously set
- Problem: Now the user cant properly interact with Window B
scope
solves this by globally registering each scope, and not removing a given block until all
scopes have removed it. This can of course be implemented on your own if you desire different
functionality.
API Overview (Advanced)
Below is the raw API to manage input blocking, though we recommend using our scope
helper in most
cases. Internally, scope
wraps these methods to provide the above behavior.
Global Mouse Block
The following allows you to block the game from receiving mouse input:
Global Cursor Override
Force the cursor to be shown or hidden:
Keyboard Block
Block the game from receiving keyboard input:
Keyboard Input Block
Block the game from receiving input from a specific key: