Skip to content
Discussion options

You must be logged in to vote

Hi @daya0576,

To extend your solution to touch events, you can simply subscribe to two more events:

hold = False

async def handle_mouse_down():
    global hold
    hold = True
    await asyncio.sleep(0.5)
    if hold:
        ui.notify("Hold")

async def handle_mouse_up():
    global hold
    hold = False

ui.button("Hold") \
    .on("mousedown", handle_mouse_down) \
    .on("mouseup", handle_mouse_up) \
    .on("touchstart", handle_mouse_down) \
    .on("touchend", handle_mouse_up)

There's one catch though: If you repeatedly click the button, there's a good chance a "hold" event will trigger because after sleeping 0.5 seconds hold is true again. We should cancel the mouse down handler a…

Replies: 2 comments 3 replies

Comment options

You must be logged in to vote
1 reply
@daya0576
Comment options

Comment options

You must be logged in to vote
2 replies
@daya0576
Comment options

@daya0576
Comment options

Answer selected by daya0576
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants