---
tags:
    - "Left"
    - "Right"
    - "Middle"
    - "Cursor"
    - "Down"
---

# Is Mouse Pressed

[Input](index.md) / **Is Mouse Pressed**

<div class="grid cards" markdown>

* :green_circle: Can Read

* :red_circle: Cannot Write

</div>

## Description

Returns true if the specified Mouse button is being held down

## Code

```cs
using System;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Controls;
using UnityEngine.InputSystem.LowLevel;
using VisualScript.Icons;

namespace VisualScript.Runtime
{
    [Get]
    
    [Inline(nameof(m_Button))]
    
    [Title("Is Mouse Pressed")]
    [Category("Input/Is Mouse Pressed")]
    
    [Description("Returns true if the specified Mouse button is being held down")]
    [Image(typeof(IconMouse), ColorTheme.Type.Blue)]
    
    [Keywords("Left", "Right", "Middle", "Cursor", "Down")]
    
    [Serializable]
    public class TypeBoolInputMousePress : TypeBool
    {
        private enum ClickCount
        {
            Single,
            Double,
            Triple
        }
        
        [SerializeField] private MouseButton m_Button = MouseButton.Left;
        [SerializeField] private ClickCount m_Clicks = ClickCount.Single;

        public override bool Get(Args args)
        {
            ButtonControl button = this.m_Button switch
            {
                MouseButton.Left => Mouse.current.leftButton,
                MouseButton.Right => Mouse.current.rightButton,
                MouseButton.Middle => Mouse.current.middleButton,
                MouseButton.Forward => Mouse.current.forwardButton,
                MouseButton.Back => Mouse.current.backButton,
                _ => throw new ArgumentOutOfRangeException()
            };

            if (button.isPressed)
            {
                int clickCount = Mouse.current.clickCount.ReadValue();
                
                switch (this.m_Clicks)
                {
                    case ClickCount.Single: return clickCount == 1;
                    case ClickCount.Double: return clickCount == 2;
                    case ClickCount.Triple: return clickCount == 3;
                    default: throw new ArgumentOutOfRangeException();
                }
            }

            return false;
        }

        public override string ToString()
        {
            return this.m_Clicks switch
            {
                ClickCount.Single => $"Pressing Mouse {this.m_Button}",
                ClickCount.Double => $"Double Pressing Mouse {this.m_Button}",
                ClickCount.Triple => $"Triple Pressing Mouse {this.m_Button}",
                _ => throw new ArgumentOutOfRangeException()
            };
        }
        
        protected override SubscriptionMode Subscription => SubscriptionMode.OnChange;
    }
}
```

