This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
GemCow's profile picture

Detect how long the mouse is clicked

Started by GemCow, 20 October 2015 - 09:57 AM
GemCow #1
Posted 20 October 2015 - 11:57 AM
In my game

local Sec
Sec = 0
while true do
Local event, x, y = os.pullEvent("mouse_clicked")
If event == "mouse_clicked" and x < 3 or event == "mouse_drag" and x < 3 then
Sec = Sec + 1
sleep(1)
end
end

how do I detect how long the mouse is HELD down
Edited on 20 October 2015 - 10:02 AM
Bomb Bloke #2
Posted 20 October 2015 - 12:12 PM
It's only possible as of CC 1.74, thanks to the introduction of the mouse_up event. By checking os.clock() when a mouse_click (not "mouse_clicked"!) event is pulled, and comparing that value to os.clock() when mouse_up is pulled, you can determine the amount of time for which the button was held.

That said, depending on the nature of your game, you might simply be able to measure the amount of time between one mouse_click event and another mouse_click event.