A keyboard key or a mouse key.
thanks
There is a way to detect how long a key is pressed?
Re: There is a way to detect how long a key is pressed?
I quess no direct command for that, but you can program it:
Code: Select all
EscapeQuit(True)
StartTimer(1)
Repeat
If IsLeftMouse() = True
ResetTimer(1)
endloop=False
Repeat
If IsLeftMouse() = False Then endloop=True
Until endloop=True
timeittook = GetTimer(1)
DebugPrint("left mouse button was down for "..timeittook.." milliseconds")
EndIf
Forever
Re: There is a way to detect how long a key is pressed?
Although the previous example has some busy loops which you should always avoid Add at least some waits there...
Or you could do it by events like this:
Or you could do it by events like this:
Code: Select all
Function p_Input(msg)
Switch msg.Action
Case "OnMouseDown":
StartTimer(1)
Case "OnMouseUp":
DebugPrint("Mouse was pressed for " .. GetTimer(1) .. " milliseconds.")
StopTimer(1)
Case "OnKeyDown":
StartTimer(2)
Case "OnKeyUp":
DebugPrint("A key was pressed for " .. GetTimer(2) .. " milliseconds.")
StopTimer(2)
EndSwitch
EndFunction
EscapeQuit(True)
InstallEventHandler({OnMouseDown = p_Input, OnMouseUp = p_Input, OnKeyDown = p_Input, OnKeyUp = p_Input})
Repeat
WaitEvent
Forever
- airsoftsoftwair
- Posts: 5446
- Joined: Fri Feb 12, 2010 2:33 pm
- Location: Germany
- Contact:
Re: There is a way to detect how long a key is pressed?
+1 for jPV's solution
Re: There is a way to detect how long a key is pressed?
It works thanks