Is it possible to disable a key?

Hey, I need to disable the input of the following keys:

A D Space and Mouseclick 1

Is this possible and if so is their a script reference I can check out?

Thanks in advance :slight_smile:

Not really, particularly since there are a couple of different ways to do keyboard input (through Buttons or directly via Keys)

There are two ways around it though.

  • The simplest way would be to disable
    the Component that is looking for
    those particular keys. For example,
    if you are using the FPS movement
    controller that comes with Unity, you
    could simply set it’s “Active”
    property to ‘false’. This works well
    when you want to disable ALL of the
    functions of a component, but isn’t
    useful if you only want to shut down

  • Otherwise, get hacking - search for
    where the key is used (ie.
    Input.GetMouseButtonxxx or
    Input.GetKeyxxx etc.) and add an
    extra condition to the if statement -
    something that checks a global flag
    to see if it should be enabled or

At a later stage you may decide to allow users to re-map controls via the Input panel (if you are making a standalone build), so disabling specific keys may not be suitable.

So for example, let’s say we have a static property on one of our objects called ‘ButtonsEnabled’…

class GlobalObject
    public static bool ButtonsEnabled = true;

Then you could simply check it’s value every time someone checks for one of the important buttons.

if ((Input.MouseButtonDown(0)) && (GlobalObject.ButtonsEnabled == true)) {
    //Response To The Button