---
tags:
    - "Mouse"
    - "Pointer"
    - "Lock"
    - "Unlock"
    - "Confine"
    - "Free"
    - "Capture"
---

# Set Cursor Lock State

[Input](../index.md) / [Cursor](index.md) / **Set Cursor Lock State**

## Description

Changes whether the mouse cursor is locked to the center of the view, confined to the window or free

## Parameters

| Name | Description |
| :--- | :---------- |
| Lock State | Locked keeps the cursor at the center of the view, Confined keeps it inside the window and None frees it |

## Code

```cs
using System;
using UnityEngine;
using VisualScript.Icons;

namespace VisualScript.Runtime
{
    [Title("Set Cursor Lock State")]
    [Category("Input/Cursor/Lock State")]
    [Description("Changes whether the mouse cursor is locked to the center of the view, confined to the window or free")]

    [Image(typeof(IconCursor), ColorTheme.Type.Blue)]
    [Keywords("Mouse", "Pointer", "Lock", "Unlock", "Confine", "Free", "Capture")]

    [Parameter("Lock State", "Locked keeps the cursor at the center of the view, Confined keeps it inside the window and None frees it")]

    [Serializable]
    public class InstructionCursorSetLockState : Instruction
    {
        [SerializeField] private CursorLockMode m_LockState = CursorLockMode.Locked;

        protected override string GetTitle(GameObject source)
        {
            string className = TextUtils.ThemeAsKeyword("Cursor");
            string member = TextUtils.ThemeAsKeyword("Lock State");
            return $"{className} {member} = {this.m_LockState}";
        }

        protected override Awaitable Run(Args args)
        {
            Cursor.lockState = this.m_LockState;
            return Done;
        }
    }
}
```

