# Detecting OnClick (= down and up happening on the same UMG Widget)

**URL:** <https://forums.unrealengine.com/t/detecting-onclick-down-and-up-happening-on-the-same-umg-widget/401875>\
**Category:** UI\
**Tags:** onclick, unreal-engine, Widget, question\
**Created:** [August 12, 2017, 11:27am UTC](https://forums.unrealengine.com/t/detecting-onclick-down-and-up-happening-on-the-same-umg-widget/401875 "2017-08-12T11:27:29Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Roi\_Danton](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Roi\_Danton](https://forums.unrealengine.com/u/Roi_Danton)\
**Post date:** [August 12, 2017, 11:27am UTC](https://forums.unrealengine.com/t/detecting-onclick-down-and-up-happening-on-the-same-umg-widget/401875/1 "2017-08-12T11:27:29Z")

</div>

UMG offers OnMouseDown/OnTouchStarted/OnKeyDown and OnMouseUp/OnTouchEnded/OnKeyUp (and the native versions for C++ programming). I want to detect if \*down and \*up happened on the very same widget.

My naive idea is to store the widget where the \*down happened in the event (if possible?) and compare this to up. However this causes the need to store a pointer somewhere.

A second possibility would be to `GetCursorDelta()` of the `FPointerEvent` but this method heavily depends on widgets size and \*down position. So this is worse than the first idea.

Do `FGeometry` and/or `FPointerEvent` (or some other class I am not aware of yet) allow a method for detecting if \*up happens on the same widget as the causing \*down event happened?

---

<div class="post-metadata">

**Author:** ![Roi\_Danton](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Roi\_Danton](https://forums.unrealengine.com/u/Roi_Danton)\
**Post date:** [August 12, 2017, 7:56pm UTC](https://forums.unrealengine.com/t/detecting-onclick-down-and-up-happening-on-the-same-umg-widget/401875/2 "2017-08-12T19:56:12Z")

</div>

After trying [`FWidgetPath`](https://docs.unrealengine.com/latest/INT/API/Runtime/SlateCore/Layout/FWidgetPath/index.html) of the `FPointerEvent` (which isn’t the path of the event but the path of the current widget! 😉 ) and experiments with `FPointerEvent::GetCursorDelta()` (which didn’t work in my case since other events are called on same widget when entering, so the length of the `FVector` was zero), I’ve opted in for my first idea.

It works. Basically I’ve done

```
FReply UMyWidget::NativeOnMouseButtonDown(const FGeometry& InGeometry, const FPointerEvent& InMouseEvent)
{
    //...
    this->inputDownDetected = true;
    //...
}
    
    FReply UMyWidget::NativeOnMouseButtonUp(const FGeometry& InGeometry, const FPointerEvent& InMouseEvent)
    {
        //...
        if (this->inputDownDetected)
        {
            this->DoSomethingOnClick();
        }
        someParentWidget->SetChildrenInputDownDetectedToFalse();

        //...
    }

```

If there are better/built in ways to handle OnClick, please share. Thanks!
