# Simulate a mouse Click?

**URL:** <https://discussions.unity.com/t/simulate-a-mouse-click/97796>\
**Category:** Questions & Answers\
**Created:** [March 1, 2014, 11:07pm UTC](https://discussions.unity.com/t/simulate-a-mouse-click/97796 "2014-03-01T23:07:00Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![BillyJazz](https://avatars.discourse-cdn.com/v4/letter/b/ecd19e/32.png) [@BillyJazz](https://discussions.unity.com/u/BillyJazz)\
**Post date:** [March 1, 2014, 11:07pm UTC](https://discussions.unity.com/t/simulate-a-mouse-click/97796/1 "2014-03-01T23:07:00Z")

</div>

I am have been making a game solely for pc, i have now come to the point id like to implement joystick, I’ve done so successfully with every key binding, however my game comprises of mouse clicks, OnMouseUp to be precise, and I am stumped how to accomplish this, i merely want to have for example:

if (input.GetButtonDown(“A”) {

//simulate mouse click in general

}

Which would then effect my OnMouseUp scripts through out the game as if the mouse it self was clicked.

This i would have thought was simple as my cursor is locked to the centre of the screen, my mouse enters and exit codes work fine and prove this, its just getting the mouse to click i cant do, please help its like the last thing on the to do list 😛

---

<div class="post-metadata">

**Author:** ![KrystofT](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/krystoft/32/906539_2.png) [@KrystofT](https://discussions.unity.com/u/KrystofT)\
**Post date:** [August 28, 2021, 1:23pm UTC](https://discussions.unity.com/t/simulate-a-mouse-click/97796/3 "2021-08-28T13:23:43Z")

</div>

This is an old question, but it was quite hard to find this as a solution. So hope this will help someone. Also, with the new Input System, it might be even easier.

* * *

To put it simply. You can inherit your own class from `StandaloneInputModule`. And there you are able to call `ProcessTouchPress` which will resolve into a clicking action. In general i would recommend looking through [the source code](https://github.com/Unity-Technologies/uGUI) of the Unity UI system which contains the EventSystem.

* * *

```
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;

public class TestInputModule : StandaloneInputModule
{
    public void ClickAt(float x, float y)
    {
        Input.simulateMouseWithTouches = true;
        var pointerData = GetTouchPointerEventData(new Touch() 
        {
            position = new Vector2(x, y),
        }, out bool b, out bool bb);

        ProcessTouchPress(pointerData, true, true);
    }

    void Update()
    {
        if(Input.GetKeyDown(KeyCode.F1))
        {
            ClickAt(Screen.width / 2, Screen.height / 2);
        }
    }
}

```

---

<div class="post-metadata">

**Author:** ![vexe](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/vexe/32/399107_2.png) [@vexe](https://discussions.unity.com/u/vexe)\
**Post date:** [March 2, 2014, 5:07pm UTC](https://discussions.unity.com/t/simulate-a-mouse-click/97796/2 "2014-03-02T17:07:07Z")

</div>

This already have been answered [How can I control the mouse (Move and send mouse click signals) via the keyboard](http://answers.unity3d.com/questions/564664/how-i-can-move-mouse-cursor-without-mouse-but-with.html) (Specifically for PC - For sending mouse event via buttons, see 2nd edit)
