Jump to content

I need help with detecting mouse and keyboard input


Danjen
 Share

Recommended Posts

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
Link to comment
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
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...