You can set a field in the button instance to keep track of the pressed status :
local btn = ui.Button(win, "Click Me")
btn.left_pressed = false
function btn:onMouseUp()
btn.left_pressed = false
end
function btn:onMouseDown()
btn.left_pressed = true
end
function btn:onLeftPress()
-- do what you need to do
end
ui.run(win)
async(function()
while win.visible do
if btn.left_pressed then
btn:onLeftPress()
end
sleep(300)
end
end)
waitall()