# How to: Detect multi-touch events using a custom operator (HPS)

**URL:** <https://forum.techsoft3d.com/t/how-to-detect-multi-touch-events-using-a-custom-operator-hps/5076>\
**Category:** HOOPS Visualize Desktop\
**Tags:** code, sample, knowledge-base, how-to\
**Created:** [February 3, 2026, 11:31pm UTC](https://forum.techsoft3d.com/t/how-to-detect-multi-touch-events-using-a-custom-operator-hps/5076 "2026-02-03T23:31:50Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![simon](https://avatars.discourse-cdn.com/v4/letter/s/f07891/32.png) [@simon](https://forum.techsoft3d.com/u/simon)\
**Post date:** [February 3, 2026, 11:31pm UTC](https://forum.techsoft3d.com/t/how-to-detect-multi-touch-events-using-a-custom-operator-hps/5076/1 "2026-02-03T23:31:50Z")

</div>

Below is sample code that detect multi-touch events using a custom operator.

```auto
class MyCustomTapOperator : public HPS::Operator
{
public:
    MyCustomTapOperator(HPS::Canvas c) : canvas(c) {

        tapCount=0;
        doubleTap_detected=false;
        tripleTap_detected= false;

    }
    bool OnTouchDown(HPS::TouchState const& in_state)
    {

        canvas.GetFrontView().GetSegmentKey().GetCameraControl().SetUpVector(HPS::Vector(0,1,0));

        // add tap count
        tapCount++;

        if (tapCount == 1)
        {
            doubleTap_detected=false;
            tripleTap_detected=false;
        }

        // check for time delay on double tap
        else if (tapCount == 2)
        {
            end = HPS::Database::GetTime();
            elapse = end - start;

            if (elapse < 500)
            {
                doubleTap_detected = true;
            }
            else // pass elapse time, restart tapCount
            {

                tapCount=1;
            }
        }
        //check for time delay on triple tap
        else if (tapCount == 3)
        {
            end = HPS::Database::GetTime();
            elapse = end - start;

            if (elapse < 700)
            {
                tripleTap_detected = true;
            }
            else // pass elapse time, restart tapCount
            {
                tapCount=1;
            }
        }

        // Flush model
        HPS::SegmentKey modelKey = canvas.GetFrontView().GetAttachedModel().GetSegmentKey();
        modelKey.Subsegment("text").Flush();
        modelKey.GetVisibilityControl().SetText(true);
        modelKey.GetTextAttributeControl().SetFont("ts3d").SetBold(true).SetAlignment(HPS::Text::Alignment::Center);
        modelKey.Subsegment("main").Flush(HPS::Search::Type::Everything, HPS::Search::Space::SubsegmentsAndIncludes);

        // Action for single tap
        if (tapCount == 1)
        {

            //Start timer
            start = HPS::Database::GetTime();
            modelKey.Subsegment("text").InsertText(HPS::Point(0, 0, 0), "Single Tap");

        }
        // Action for double tap
        else if (tapCount == 2)
        {
            if (doubleTap_detected) {

                modelKey.Subsegment("text").InsertText(HPS::Point(0, 0, 0), "Double Tap");

            }

        }

        // // Action for triple tap
        else if (tapCount == 3)
        {
            if (tripleTap_detected) {

                canvas.GetFrontView().FitWorld().UpdateWithNotifier().Wait();
                modelKey.Subsegment("text").InsertText(HPS::Point(0, 0, 0), "Triple Tap");
            }

        }

        canvas.UpdateWithNotifier().Wait();

        return true;
    }

    bool OnTouchUp(HPS::TouchState const& in_state) {

        HPS::SegmentKey modelKey = canvas.GetFrontView().GetAttachedModel().GetSegmentKey();
        modelKey.Subsegment("text").GetMaterialMappingControl().SetTextColor(HPS::RGBAColor(1,0,0));

        if (tripleTap_detected)
        {
            // reset
            doubleTap_detected=false;
            tripleTap_detected=false;
            tapCount=0;
        }

        canvas.UpdateWithNotifier().Wait();
        return true;
    }

private:
    HPS::Canvas canvas;

    bool doubleTap_detected;

    bool tripleTap_detected;

    HPS::Time start;
    HPS::Time end;
    HPS::Time elapse;
    size_t tapCount;

};

```
