Jump to content

Mouse movement capture problem


Recommended Posts

Hello, I have a problem in this code that I am making. I am not too good in using GUI but I think I'm ok at it. Please help.

Case $msg = $stop
        $go = 0
        $rec = 0
        GUICtrlSetState($stop, $GUI_DISABLE)
        GUICtrlSetState($start, $GUI_ENABLE)
        GUICtrlSetState($playback, $GUI_ENABLE)
        GUICtrlSetData($recording, "Recording: Off  Frame:" & $all1)
        
        
    Case $msg = $start
        
        
        
        $rec = 1
        GUICtrlSetState($start, $GUI_DISABLE)
        GUICtrlSetState($stop, $GUI_ENABLE)
        GUICtrlSetState($playback, $GUI_DISABLE)
        
        
        While $rec = 1
            $readx1 = FileRead("Mousex.txt")
            $splitx1 = StringSplit($readx1, ":")
            $all1 = $splitx1[0]

        $mpos = MouseGetPos()
        FileWrite("Mousex.txt", $mpos[0] & ":")
        FileWrite("Mousey.txt", $mpos[1] & ":")
        Sleep(27)
        GUICtrlSetData($recording, "Recording: On  Frame:" & $all1)
    WEnd

When I press "Start" it works perfectly but when I press "Stop" it seems like $rec stays at 1 and doesn't let me stop it. I tried it without While and just If $rec = 1 and that only let me do one frame.

I need it so it will keep going but I will be able to stop it when I press stop. Is there a way to loop it like that?

Link to comment
Share on other sites

check $msg in your while loop? seems like a hard problem indeed and i dont know if this will fix, but it seems to make sense. Your program is stuck in the while loop because you never set rec to 0. ONLY when the while loop ends can you check your cases again, this is why your code isnt allowing you to press stop.

Link to comment
Share on other sites

While $rec = 1
    $readx1 = FileRead("Mousex.txt")
    $splitx1 = StringSplit($readx1, ":")
    $all1 = $splitx1[0]

    $mpos = MouseGetPos()
    FileWrite("Mousex.txt", $mpos[0] & ":")
    FileWrite("Mousey.txt", $mpos[1] & ":")
    Sleep(27)
    GUICtrlSetData($recording, "Recording: On  Frame:" & $all1)

    Sleep(10) ;<-- recommended
    If GUIGetMsg() = $stop Then $rec = 0 ;<-- added line
    
WEnd

Assuming the value of $msg is of GUIGetMsg(),

Edited by Mison

Hi ;)

Link to comment
Share on other sites

I do have $rec set as 0 =[ that's not all of the code of course.

But you dont do it in the while loop. Your script will never read your clicking the stop button. the while loop needs to end first. This is why i am giving you alternate methods. You either need to set rec to 0 somehow or modify your while loop.
Link to comment
Share on other sites

You would like to record and playback mouse movement/clicks?

Take a look into my signature. ;)

_Mouse UDF.

Minesweeper

A minesweeper game created in autoit, source available.

_Mouse_UDF

An UDF for registering functions to mouse events, made in pure autoit.

2D Hitbox Editor

A 2D hitbox editor for quick creation of 2D sphere and rectangle hitboxes.

Link to comment
Share on other sites

if you push start before then it will not function if you push stop. the loop you have in start is inifinite. ExitLoop function. add these there.

$msg = GUIGetMsg() 
if $msg = $stop then 
exitloop 
endif

and i see while $rec = 1

you have to declare a new variable -> $rec <- so it could exit the loop so thats how its infinite.

Edited by Zibit
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...