Sign in to follow this  
Followers 0
UnknownWarrior

Ini is not writing down correct values...

24 posts in this topic

When I record my x and y coordinates it is recording an extra x, y out of no where... Ever since I added in my time factor that records the time in between clicks, its been giving me this glitch...

#include <misc.au3>

;Opt("MouseCoordMode",2)


Global $x=false, $tick=1, $hi=false, $read=1, $timer=0
If FileExists(@scriptdir&"\Coords.ini") Then
    FileDelete(@scriptdir&"\Coords.ini")
EndIf 


While 1
HotKeySet("{F5}","Record")
HotKeySet("{F6}","StartStop")
HotKeySet("{ESC}","ExitNow")
Wend

Func Record()
    If $x=true Then
        $x=False;--- 
        $exitm=MsgBox(4, "Stopped", "You have stopped your recording...Would you like to save?")
            If $exitm=6 Then
                $stream=InputBox("Save As","What name would you like to save it as?","")
                If @error Then
                    Sleep(500)
                    MsgBox(0,"Alright...","It's highly recommended to save. You may save after you exit the bot")
                Else
                FileMove(@ScriptDir&"\Coords.ini",@ScriptDir&"\"&$stream&".ini",9) 
                endif
            endif
    elseif $x=false Then
        $x=true
        msgbox(0,"","Starting record")
    endif
    While $x=true
        Do
        If _IsPressed("01") Then
            $timer=TimerInit()
            $pos=MouseGetPos()
            IniWrite("Coords.ini","Coords","x"&$tick,$pos[0]) 
            IniWrite("Coords.ini","Coords","y"&$tick,$pos[1]) 
        EndIf
    Until _IsPressed("53")
    Sleep(200)
    If not $timer=0 Then
        $kill=TimerDiff($timer)
        IniWrite("Coords.ini","Coords","time"&$tick, $kill) 
    sleep(5)
    $tick=$tick+1
    endif
    Wend
EndFunc

I've posted a few threads and no one is bothering to help me... I'm giving my code, I'm giving my exact question, why doesn't anyone ever want to give some help? At least I don't come in here like some noob begging for a program... I have a glitch here and I'm asking for you guys to help me solve why it is doing it...

Heres a look at my ini file:

[Coords]
x1=726
y1=430
time1=4234.35638996796
x2=757
y2=422
time2=1754.41300370563
x3=742
y3=512

And it is writing down 3 x,y's when I only clicked 2 times... For some reason its recording a random click nearby my other 2 clicks and writing that down for some reason... Any ideas?

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

its because _ispressed is looping back to fast before you release the mouse button, add a sleep in there and it'll work.

If _IsPressed("01") Then
            $timer=TimerInit()
            $pos=MouseGetPos()
            IniWrite("Coords.ini","Coords","x"&$tick,$pos[0])
            IniWrite("Coords.ini","Coords","y"&$tick,$pos[1])
            sleep(60)
        EndIf

the same thing happens for keyboard strokes then using _ispressed and writing that to a file.

Edited by Rental

Share this post


Link to post
Share on other sites

Lol I think I got your problem :) Try doing this:

ElseIf $x = False Then
        $x = True
        MsgBox(0, "", "Starting record")


        while _isPressed("01")
            sleep(1)
        wend[/b]


    EndIf

What I'm guessing is that since when you click the OK button in the msgbox, the box goes away and IMMEDIATELY (ok, in 1/10000 of a sec maybe) the while loop starts, the do loop starts, and the If _IsPressed("01") there triggers the first click recording because your finger has not left the mouse button yet, from clicking the OK button.


Roses are FF0000, violets are 0000FF... All my base are belong to you.

Share this post


Link to post
Share on other sites

its because _ispressed is looping back to fast before you release the mouse button, add a sleep in there and it'll work.

If _IsPressed("01") Then
            $timer=TimerInit()
            $pos=MouseGetPos()
            IniWrite("Coords.ini","Coords","x"&$tick,$pos[0])
            IniWrite("Coords.ini","Coords","y"&$tick,$pos[1])
            sleep(60)
        EndIf

the same thing happens for keyboard strokes then using _ispressed and writing that to a file.

I thought that first too but thats not exactly it - he already thought of that and added Sleep(200) in the code. I am guessing that my solutoin is the thing :)

Roses are FF0000, violets are 0000FF... All my base are belong to you.

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

I thought that first too but thats not exactly it - he already thought of that and added Sleep(200) in the code. I am guessing that my solutoin is the thing :)

Correct on that part...

But I did have a Sleep in previous testings with a sleep of (200) before the timerInit... Either way I did test it with a big sleep for safe measures and I got the same results...

Heres with clicking THREE times...

[Coords]
x1=397
y1=387
time1=1075.26013927427
x2=440
y2=359
time2=978.652625624318
x3=348
y3=464
time3=804.16229319203
x4=530
y4=640

And heres what I changed:

elseif $x=false Then
        $x=true
        msgbox(0,"","Starting record")
        Sleep(1000)
    endif

(Added in a whole second... :s)

From previous testings I noticed that imaginary click comes out of no where but it is within a certain range of any of my clicks....

Say: If I click A on my screen, that imaginary puts down also the coords of B... No idea why.... My earlier bot that excludes the timer DOES work indeed... I click 4 times, it records 4 x, y's... I click 55 times, it records 55 x, y's... So It has to do with something the timer did to the script... But that is the question... WHAT is it doing that changed it to make this glitch happen... :)

A ......... B

Edited by UnknownWarrior

Share this post


Link to post
Share on other sites

Put the Sleep(200) as the last line in the if _IsPressed("01") code itself, Rental was probably right after all :)

I missed the fact that the recording loop goes on without a sleep (thus maybe recording 2 coordinates if you click too long), and that the sleep only happens after you press the S key. You don't need a sleep after the S-key is pressed, you need it after a left-click was recorded.

More elegant than the sleep would be a loop that waits for the left mouse button to be released:

If _IsPressed("01") Then

$timer = TimerInit()

$pos = MouseGetPos()

IniWrite("Coords.ini", "Coords", "x" & $tick, $pos[0])

IniWrite("Coords.ini", "Coords", "y" & $tick, $pos[1])

; sleep(200)

while _isPressed("01")

wend

EndIf


Roses are FF0000, violets are 0000FF... All my base are belong to you.

Share this post


Link to post
Share on other sites

Put the Sleep(200) as the last line in the if _IsPressed("01") code itself, Rental was probably right after all :)

I missed the fact that the recording loop goes on without a sleep (thus maybe recording 2 coordinates if you click too long), and that the sleep only happens after you press the S key. You don't need a sleep after the S-key is pressed, you need it after a left-click was recorded.

More elegant than the sleep would be a loop that waits for the left mouse button to be released:

If _IsPressed("01") Then

$timer = TimerInit()

$pos = MouseGetPos()

IniWrite("Coords.ini", "Coords", "x" & $tick, $pos[0])

IniWrite("Coords.ini", "Coords", "y" & $tick, $pos[1])

; sleep(200)

while _isPressed("01")

wend

EndIf

I've thought of all these... They just aren't working for me... It cannot be anything to do with all of it EXCEPT:

If not $timer=0 Then
        $kill=TimerDiff($timer)
        IniWrite("Coords.ini","Coords","time"&$tick, $kill)

and

$timer=TimerInit()

Because If I take those out, it records them perfectly fine... When they are in there, this glitch appears.... :S

Share this post


Link to post
Share on other sites

Well I found what value is the glitching value... It's the very last recorded one AND its with x530-550 and y630-650

I do not know what is causing that random value to be put in my ini file though... ><

Share this post


Link to post
Share on other sites

Bump.... Any ideas? :)

Share this post


Link to post
Share on other sites

Why won't ANYONE help me.... :)

Share this post


Link to post
Share on other sites

SHhould the HotKeySet statements be within an infinite loop?

That doesn't matter... That just keeps the program alive... I could put Sleep(10) but that would just add to all the other Sleeps that I have which keeps piling up...

Anyone... Please help me ><

Share this post


Link to post
Share on other sites

#15 ·  Posted (edited)

You'll get notification in the console when u start recording with F11, and press Mouse Left click, just translate ConsoleWrite command into IniWrite.

#include <misc.au3>
HotKeySet("{F11}", "start_recording")
HotKeySet("{F10}", "stop_recording")
HotKeySet("{F9}", "display_recorded")
HotKeySet("{ESC}", "_quit")
Global $recording = 0, $tick = 0, $time, $timer, $text = "", $temp_text = "", $Display_time
TrayTip("", "Press F11 for start recording," & @CRLF & "then Mouse Left click to detect" & @CRLF _
            & "Press F10 to stop recording" & @CRLF & "Press F9 to see recorded" & @CRLF & "press ESC to quit", 30)
While 1
    if $recording Then
        if _IsPressed("01") then
            $time = TimerDiff($timer)
            $pos=MouseGetPos()
            $tick += 1
            $Display_time = Round(TimerDiff($timer), 2)
            if $tick = 1 then $Display_time = 0
            $temp_text = ">==========" & @CRLF & "Section: Coords" & @CRLF & "key: x" & $tick & " = " & $pos[0] _
                        & @CRLF & "key: y" & $tick & " = " & $pos[1] _
                        & @CRLF & "key: time" & $tick & " = " & $Display_time & @CRLF & ">==========" & @CRLF
            $text &= ">==========" & @CRLF & "Section: Coords" & @CRLF & "key: x" & $tick & " = " & $pos[0] _
                        & @CRLF & "key: y" & $tick & " = " & $pos[1] _
                        & @CRLF & "key: time" & $tick & " = " & $Display_time & @CRLF & ">==========" & @CRLF
            ConsoleWrite($temp_text)
            $timer=TimerInit()
            Do                          ;put this Do Until bellow _IsPressed (line 11) if you wanna detect when user release the
            Until NOT _IsPressed("01")  ;left click, or let it stay here if you wanna detect the moment user hit the left click
        EndIf
    EndIf
WEnd
func display_recorded()
    MsgBox(0, "recorded text:", $text)
EndFunc
func start_recording()
    $recording = 1
    ConsoleWrite(">=====" & @CRLF & "Recording Started" & @CRLF & ">=====" & @CRLF)
EndFunc
func stop_recording()
    $recording = 0
    ConsoleWrite(">=====" & @CRLF & "Recording Stopped" & @CRLF & ">=====" & @CRLF)
EndFunc
func _quit()
    Exit
EndFunc
Edited by sandin

Share this post


Link to post
Share on other sites

#16 ·  Posted (edited)

While $x = true     
        Do          
            If _IsPressed( "01" , $dll = DllOpen("user32.dll") ) Then; left mouse button                
                SLeep( 250 )                
                $timer=TimerInit()
                $pos=MouseGetPos()
                IniWrite( "Coords.ini" , "Coords" , "x: " & $tick & " " , $pos[ 0 ] )
                IniWrite( "Coords.ini" , "Coords" , "y: " & $tick & " " , $pos[ 1 ] )               
                If $timer <> 0 Then         
                    $kill = TimerDiff( $timer )
                    IniWrite( "Coords.ini" , "Coords" , "time: " & $tick & " " , $kill )
                    sleep( 5 )
                    $tick += 1                  
                endif               
            EndIf           
        Until _IsPressed( "53" ); 'S' key               
    Wend    
EndFunc

DllClose( $dll )

I was able to get it to work right on my machine by making these small modifications.

EDIT: no I wasn't, nevermind.... I'm still new to all of this programming stuff

Edited by jaberwocky6669

Share this post


Link to post
Share on other sites

if u use sleep(250) bellow _IsPressed, that will work, but only if u press your left mouse click not longer than 250ms, it would be advisable to put

Do

;nothing

Until NOT _isPressed

if you know what I mean.

anyway, look at my example: previous page

I see your example! That is awesome. I learned something from your code. =D

Share this post


Link to post
Share on other sites

I'm glad you did.

Anyway try removing that

Do

Until NOT _isPressed

part of the code from my example, and see what happens, that was the problem in your script, your script is writing new data into ini files as long as you HOLD (not press) mouse left click (that's why you had multiple inputs instead of only one), and Do -> Until will prevent that, and translate _IsPressed into single click.

Share this post


Link to post
Share on other sites

I'm glad you did.

Anyway try removing that

Do

Until NOT _isPressed

part of the code from my example, and see what happens, that was the problem in your script, your script is writing new data into ini files as long as you HOLD (not press) mouse left click (that's why you had multiple inputs instead of only one), and Do -> Until will prevent that, and translate _IsPressed into single click.

I really don't wanna be the hater here but that cannot be the problem... I have made at least 40+ tests changing small bits here and there... And What I've noticed its the LAST x, y recorded in the ini is the part thats not working... You may say, yes use my script from previous page because its recording you holding down the MouseClick, not the click itself... But that is not the case here. Everytime, whether I record 5 clicks or 100000 clicks, the LAST one is the glitched one and is always between x530-550, y 530-550... So that being said, it is not recording the holding down of the MouseClick because that would give me values in the same spot as the spot I clicked at, but it is making up some random fool click that is coming out of my butt somewhere...

Heres the entire script so you can work with that instead of just one function:

#include <misc.au3>

;Opt("MouseCoordMode",2)


Global $x=false, $tick=1, $hi=false, $read=1, $timer=0
If FileExists(@scriptdir&"\Coords.ini") Then
    FileDelete(@scriptdir&"\Coords.ini")
EndIf 


While 1
HotKeySet("{F5}","Record")
HotKeySet("{F6}","StartStop")
HotKeySet("{ESC}","ExitNow")
Wend


Func ExitNow()
    $exitm1=MsgBox(4, "Exiting", "Would You like to save again?")
            If $exitm1=6 Then
                $stream=InputBox("Save As","What name would you like to save it as?","")
                If @error Then
                    Exit
                Else
                FileMove(@ScriptDir&"\Coords.ini",@ScriptDir&"\"&$stream&".ini",9) 
                endif
            endif
Exit;--
EndFunc


Func Record()
    If $x=true Then
        $x=False;--- 
        $exitm=MsgBox(4, "Stopped", "You have stopped your recording...Would you like to save?")
            If $exitm=6 Then
                $stream=InputBox("Save As","What name would you like to save it as?","")
                If @error Then
                    Sleep(500)
                    MsgBox(0,"Alright...","It's highly recommended to save. You may save after you exit the bot")
                Else
                FileMove(@ScriptDir&"\Coords.ini",@ScriptDir&"\"&$stream&".ini",9) 
                endif
            endif
    elseif $x=false Then
        $x=true
        
        Sleep(10)
    endif
    While $x=true
        Do
        If _IsPressed("01") Then
            $timer=TimerInit()
            $pos=MouseGetPos()
            IniWrite("Coords.ini","Coords","x"&$tick,$pos[0]) 
            IniWrite("Coords.ini","Coords","y"&$tick,$pos[1]) 
        EndIf
    Until _IsPressed("53")
    Sleep(200)
    If not $timer=0 Then
        $kill=TimerDiff($timer)
        IniWrite("Coords.ini","Coords","time"&$tick, $kill) 
    sleep(5)
    $tick=$tick+1
    endif
    Wend
EndFunc

Func StartStop()
    $read=1
    If $hi= True Then
        $hi=False
    ElseIf $hi= False Then
        $inir=FileOpenDialog("Pick a file to replay", @scriptDir, "Ini (*.ini*)")
        If @error Then
        Else
            MsgBox(0,"", "It will now replay")
            Sleep(400)
        EndIf
        $hi=True
    EndIf
        
    While $hi = True    
        $replayx=IniRead($inir, "Coords", "x"&$read, "Error" )
        if $replayx="Error" Then
            $read=1
        else
        $replayy=IniRead($inir, "Coords", "y"&$read, "Error" )
        MouseClick("left",$replayx,$replayy,1,0)
        $read=$read+1
        $inikiller=IniRead($inir, "Coords", "time"&$read, "Error" )
        Sleep($inikiller)
        endif
    WEnd    
EndFunc

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