Sign in to follow this  
Followers 0
Danjen

I need help with detecting mouse and keyboard input

4 posts in this topic

Basically what I want this to do is start a loop, and pause until the user clicks a mouse button. When that happens, the script will see where the mouse is, what button was pressed, and how long between the last click it was. Essentially, this is so that a user can record a macro, but it's not quite working correctly.

Local $MousePos[10][4]
Local $TimeSinceLast
Func GetTime()
    $TimeSinceLast = TimerInit()
EndFunc
Func GetMouse($num)
    $MousePos[$num][0] = MouseGetPos(0)
    $MousePos[$num][1] = MouseGetPos(1)
    If MouseUp("left") then $MousePos[$num][2] = "left"
    If MouseUp("right") then $MousePos[$num][2] = "right"
    $MousePos[$num][3] = TimerDiff()
    GetTime()
EndFunc
For $rep = 0 to 9
    While MouseDown("")
        Sleep(100)
    WEnd
    GetMouse($num)
Next

Share this post


Link to post
Share on other sites



Something like this?

#include <Misc.au3>

Local $TimeSinceLast=0
Local $PressedButton
Local $MousePos
Func GetTime()
    $TimeSinceLast = TimerInit()
EndFunc
Func ShowInfo()
    If $TimeSinceLast=0 Then 
        $TimeSinceLastPressed=0
    Else
    $TimeSinceLastPressed=TimerDiff($TimeSinceLast)/1000; just use $TimeSinceLast if you want it in milliseconds
    EndIf
    
    MsgBox(64,"","Button Pressed: " &$PressedButton& @CRLF & "Time Since Last Button Pressed: " &$TimeSinceLastPressed& " seconds"&@CRLF&"Mouse Position: ("&$MousePos[0]&","&$MousePos[1]&")")
    GetTime()
EndFunc

    While 1
        Sleep(15)
        If _IsPressed(01) Then
            $PressedButton="Left"
            $MousePos=MouseGetPos()
            ShowInfo()
        EndIf
        If _IsPressed(02) Then
            $PressedButton="Right"
            $MousePos=MouseGetPos()
            ShowInfo()
        EndIf
        If _IsPressed(04) Then
            $PressedButton="Middle"
            $MousePos=MouseGetPos()
            ShowInfo()
        EndIf
        
    WEnd

Share this post


Link to post
Share on other sites

@Volly: Nope wasn't aware SciTe had a macro recorder ... is it an .exe or is it through the script? And no, it's not a keylogger, it's to be a programmable macro for RuneScape.

@Nahuel: Yes, that is exactly what I needed.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0