Sign in to follow this  
Followers 0
Rydextillxixdiex

Ini Write, Read, User's Input/Mouse Position

17 posts in this topic

It has been a while since i have been taking on new Au3 projects, but i have picked up a new one and i hope to involve Ini for the first time. I have searched the forums and have come up with no substantial information regarding my concerns, even with my Ini use just being very general:

My objective is to allow the user of the application to run a "setup" exe which prompts them for crutial information, saves it to an Ini file (as a $varriable?) and then the mother application can read from the ini and use the "$varriables" saved in the ini within the script.

I hope to be able to allow the user to identify the L, R, T, B, limits of a button present on their screen via moving the mouse as well as the color beneath the mouse's potion and save all of this information to the "ini" file to be accessed in the main application later on.

I know that your mouse potion is read as: x,y so is it possible for the ini to only pick up on the "y" for your left and right, and your "x" for your top and bottom to identify the parameters of an on screen button or other item?

Thanks for any help in advanced.


...will never learn all there is to know about autoit, no worries...i came to the forums :)

Share this post


Link to post
Share on other sites



have you looked up the IniWrite, IniRead, IniWriteSection, IniReadSection functions?

Share this post


Link to post
Share on other sites

I have but i guess im just not sure how to structure the file or the "setup" that i wish to create to request the users information, OR how to actually incorporate their input with the IniWrite function.


...will never learn all there is to know about autoit, no worries...i came to the forums :)

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

something like that?

That will write your ypos...

$SettingsFile = @SCRIPTDIR & '\Settings.ini'
$pos = MouseGetPos()
$ypos  = iniWrite ( $SettingsFile, 'Poss', 'ypos', $pos[1] )
Edited by Xav

Share this post


Link to post
Share on other sites

Using what you gave me this is what i have come up with so far, however only the originally selected button actually writes to the inifile from my testing and it is buggy, It needs to reprompt for the remaining 3 variables, OR even better if the GUI could be removed all together and it would just prompt through msgboxes for the items all along that would be ideal. Is it possible to make the "iniwrite" upon selecting "ok" in the MsgBox?

#include <GUIConstants.au3>

Global $SettingsFile = @SCRIPTDIR & '\Settings.ini'
Global $pos = MouseGetPos()

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 338, 117, 193, 125)
$Y_pos = GUICtrlCreateButton("Ypos", 16, 16, 129, 33, 0)
$X_pos = GUICtrlCreateButton("Xpos", 160, 16, 153, 33, 0)
$Y_pos2 = GUICtrlCreateButton("Ypos2", 32, 80, 89, 33, 0)
$X_pos2 = GUICtrlCreateButton("Xpos2", 160, 72, 97, 33, 0)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Y_pos
            Call("Ypos")
        Case $X_pos
            Call("Xpos")
        Case $Y_pos2
            Call("Ypos2")
        Case $X_pos2
            Call("Xpos2")
    EndSwitch
WEnd

Func Ypos()
    While 1
    MsgBox("Ypos1", "Ypos1", "Move your mouse to the furthest left border", 20000)
    Sleep(20000)
    iniWrite ( $SettingsFile, 'Poss', 'ypos1', $pos[1] )
WEnd
EndFunc

Func Xpos()
    While 1
    MsgBox("Xpos1", "Xpos1", "Move your mouse to the furthest top border", 20000)
    Sleep(20000)
    iniWrite ( $SettingsFile, 'Poss', 'xpos1', $pos[0] )
WEnd
EndFunc

Func Ypos2()
    While 1
    MsgBox("Ypos2", "Ypos2", "Move your mouse to the furthest Right border", 20000)
    Sleep(20000)
    iniWrite ( $SettingsFile, 'Poss', 'ypos2', $pos[1] )
WEnd
EndFunc

Func Xpos2()
    While 1
    MsgBox("Xpos2", "Xpos2", "Move your mouse to the furthest bottom border", 20000)
    Sleep(20000)
    iniWrite ( $SettingsFile, 'Poss', 'xpos2', $pos[0] )
WEnd
EndFunc

Thanks for your help so far, we are getting there. I think i am making this more complicated than it needs to be.


...will never learn all there is to know about autoit, no worries...i came to the forums :)

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Is that what your tryin to do?

For a message box , there you go:

$pos = MouseGetPos()
MsgBox(0, "Y",  $pos[1])

Xav, no prob.

Edited by Xav

Share this post


Link to post
Share on other sites

Scratch my previous code, it was way to complex and after reviewing it i simplified it by a landslide...literally:

Global $SettingsFile = @SCRIPTDIR & '\Settings.ini'
Global $pos = MouseGetPos()


    MsgBox("Settings","Settings", "You will be prompted with four coordinate setting windows, each requesting a different border of the target button. Press ok when ready to begin settup")
    Sleep(100)
    Call("Ypos")
    Sleep(100)
    Call("Ypos2")
    Sleep(100)
    Call("Xpos")
    Sleep(100)
    Call("Xpos2")
    Sleep(100)
    Exit

Func Xpos()
    MsgBox("Xpos1", "Xpos1", "Move your mouse to the furthest left border, press enter once your mouse is in place.")
    iniWrite ( $SettingsFile, 'Poss', 'xpos1', $pos[0] )
EndFunc

Func Ypos()
    MsgBox("Ypos1", "Ypos1", "Move your mouse to the furthest top border, press enter once your mouse is in place.")
    iniWrite ( $SettingsFile, 'Poss', 'ypos1', $pos[1] )
EndFunc

Func Xpos2()
    MsgBox("Xpos2", "Xpos2", "Move your mouse to the furthest Right border. press enter once your mouse is in place.")
    iniWrite ( $SettingsFile, 'Poss', 'Xpos2', $pos[0] )
EndFunc

Func Ypos2()
    MsgBox("Ypos2", "Ypos2", "Move your mouse to the furthest bottom border, press enter once your mouse is in place.")
    iniWrite ( $SettingsFile, 'Poss', 'Ypos2', $pos[1] )
EndFunc

This works just as i would like it to, the only problem i am having now is that Xpos should be the extreme left, Ypos the extreme Top, Xpos2 the extreme Right, and Ypos2 the Extreme bottom when testing this on the border of the monitor. However this is not the case. I believe i may have my "$pos[""]" incorrect.

Almost there, just this one last bit of information will help me complete the writting portion of the coordinates.


...will never learn all there is to know about autoit, no worries...i came to the forums :)

Share this post


Link to post
Share on other sites

Pm me i'm a help you out . :)

Share this post


Link to post
Share on other sites

With my above script, as well as this one where i replace pressing enter with mouse clicks thanks to Xav hoping it would help, but i am still getting inaccurate readings.

#include <Misc.au3>
Global $dll = DllOpen("user32.dll")
Global $SettingsFile = @SCRIPTDIR & '\Settings.ini'
Global $pos = MouseGetPos()


    MsgBox("Settings","Settings", "You will be prompted with four coordinate setting windows, each requesting a different border of the target button. Press ok when ready to begin settup")
    Sleep(100)
    Call("Xpos")
    Sleep(100)
    Call("Xpos2")
    Sleep(100)
    Call("Ypos")
    Sleep(100)
    Call("Ypos2")
    Sleep(100)
    Exit

Func Xpos()
    MsgBox(0,"xpos", "Move your mouse to the furthest left border then click left mouse.")
        If _IsPressed("01", $dll) Then
        $pos = MouseGetPos()
        endif
    iniWrite ( $SettingsFile, 'Poss', 'xpos1', $pos[0] )
EndFunc

Func Ypos()
    MsgBox(1,"ypos", "Move your mouse to the furthest top border then click left")
        If _IsPressed("01", $dll) Then
        $pos = MouseGetPos()
        endif
    iniWrite ( $SettingsFile, 'Poss', 'ypos1', $pos[1] )
EndFunc

Func Xpos2()
    MsgBox(1,"xpos2", "Move your mouse to the furthest right border then click left")
        If _IsPressed("01", $dll) Then
        $pos = MouseGetPos()
        endif
    iniWrite ( $SettingsFile, 'Poss', 'xpos2', $pos[0] )
EndFunc

Func Ypos2()
    MsgBox(1,"ypos2", "Move your mouse to the furthest bottom border then click left")
        If _IsPressed("01", $dll) Then
        $pos = MouseGetPos()
        endif
    iniWrite ( $SettingsFile, 'Poss', 'ypos2', $pos[1] )
EndFunc

my results are reading:

[Poss]

xpos1=519

Xpos2=519

ypos1=315

Ypos2=315

are something simmilar to those numbers everytime while they should be reading

[Poss]

xpos1=0

Xpos2=1279

ypos1=0

Ypos2=799

That is according to autoit's very own "window info" application so i know that is the accurate borders of my screen.

Thanks for anyhelp getting this sorted out as to why it isn't giving me the data i want.


...will never learn all there is to know about autoit, no worries...i came to the forums :)

Share this post


Link to post
Share on other sites

yep i found what u needed

SplashTextOn ()

go see in help files

Share this post


Link to post
Share on other sites

This is what i came up with hoping that the text would stay on until the user "clicks":

#include <Misc.au3>
Global $dll = DllOpen("user32.dll")
Global $SettingsFile = @SCRIPTDIR & '\Settings.ini'
Global $pos = MouseGetPos()


    MsgBox("Settings","Settings", "You will be prompted with four coordinate setting windows, each requesting a different border of the target button. Press ok when ready to begin settup")
    Sleep(100)
    Call("Xpos")
    Sleep(100)
    Call("Xpos2")
    Sleep(100)
    Call("Ypos")
    Sleep(100)
    Call("Ypos2")
    Sleep(100)
    Exit

Func Xpos()
    SplashTextOn("xpos", "Move your mouse to the furthest left border then click left mouse.", -1, 100, -1, -1, 0, "verdana", 28, 450)
        If _IsPressed("01", $dll) Then
        $pos = MouseGetPos()
        SplashOff()
        endif
    iniWrite ( $SettingsFile, 'Poss', 'xpos1', $pos[0] )
EndFunc

Func Ypos()
    SplashTextOn("ypos", "Move your mouse to the furthest top border then click left", -1, 100, -1, -1, 0, "verdana", 28, 450)
        If _IsPressed("01", $dll) Then
        $pos = MouseGetPos()
        SplashOff()
        endif
    iniWrite ( $SettingsFile, 'Poss', 'ypos1', $pos[1] )
EndFunc

Func Xpos2()
    SplashTextOn("xpos2", "Move your mouse to the furthest right border then click left", -1, 100, -1, -1, 0, "verdana", 28, 450)
        If _IsPressed("01", $dll) Then
        $pos = MouseGetPos()
        SplashOff()
        endif
    iniWrite ( $SettingsFile, 'Poss', 'xpos2', $pos[0] )
EndFunc

Func Ypos2()
    SplashTextOn("ypos2", "Move your mouse to the furthest bottom border then click left", -1, 100, -1, -1, 0, "verdana", 28, 450)
        If _IsPressed("01", $dll) Then
        $pos = MouseGetPos()
        SplashOff()
        endif
    iniWrite ( $SettingsFile, 'Poss', 'ypos2', $pos[1] )
EndFunc

the window disapeeres immediately though and cycles through them real quickly and im still not sure that it is recording accurate data to the ini. file: i.e. the actual borders of the screen when i move the mouse to the appropriate position.


...will never learn all there is to know about autoit, no worries...i came to the forums :)

Share this post


Link to post
Share on other sites

try it out , i didnt try.

Func Xpos()
SplashTextOn("xpos", "Move your mouse to the furthest left border then click left mouse.", -1, 100, -1, -1, 0, "verdana", 28, 450)
        If _IsPressed("01", $dll) Then
        $pos = MouseGetPos()
        elseif _IsPressed("01", $dll) then 
         call("Ypos")
        SplashOff()
         Endif
        EndIf
    iniWrite ( $SettingsFile, 'Poss', 'xpos1', $pos[0] )
EndFunc

Share this post


Link to post
Share on other sites

This didn't help, it still just cycles through each function quickly and doesn't wait until the user clicks : /.

Thanks for being patient and providing your help.


...will never learn all there is to know about autoit, no worries...i came to the forums :)

Share this post


Link to post
Share on other sites

BUMP - sorry :)

Recap:

My objective is to create a "setup" application for a mother program that prompts the user to move their mouse to specified regions of a field: i.e. extreme left, right, top, bottom and save the coordinates to an ini. file. I how ever only want the Y or the X saved depending on the requested placement. For example, the left margin would only need the "x" value recorded while the top margin would only need the "y" value recorded.

As you can see from my script(s) and from the help of Xav we have come up with many different methods non of which have proven workable yet. The current script advances before the mouse is clicked, and advances so fast that it is finished in about 2 seconds. Also, previous scripts such as one of my original "click then press enter to continue" with the msgbox would record in-accurate data as showed by my ini file data in a previous post, as well as the provided values the ini should contain when testing on the border of my screen.

I need guidance in revising my script to work properly or need assistance in writting this scripting in a better way.


...will never learn all there is to know about autoit, no worries...i came to the forums :)

Share this post


Link to post
Share on other sites

#15 ·  Posted (edited)

Here's what was happening: when the script first run, there was the global definition for $pos, which captured the mouse position when the script started.

Later in your script, the "if _IsPressed()" would redefine the $pos variable only if the mouse button was pressed down. There was no code to get it to wait for the mouse button, so it immediately saved values from the $pos that was defined at the start of the script, and carried on.

I implemented two While loops. The first waits for the mouse button to be pressed down, then the second waits for it to be released. This keeps the script from blasting through all the steps when you press the button for the first step.

I also changed the font size on the SplashText window to 18 because it was clipping. I also inserted a @LF on the first msgbox to break things up a bit.

Note: Some of the code may need to be tidied up.

#include <Misc.au3>
Global $dll = DllOpen("user32.dll")
Global $SettingsFile = @SCRIPTDIR & '\Settings.ini'

    MsgBox("Settings","Settings", "You will be prompted with four coordinate setting windows, each requesting a different border of the target button."&@LF&" Press ok when ready to begin setup")
    Sleep(100)
    Call("Xpos")
    Sleep(100)
    Call("Xpos2")
    Sleep(100)
    Call("Ypos")
    Sleep(100)
    Call("Ypos2")
    Sleep(100)
    Exit

Func Xpos()
    SplashTextOn("xpos", "Move your mouse to the furthest left border then click left mouse.", -1, 100, -1, -1, 0, "verdana", 18, 450)
    While _IsPressed("01", $dll) =0 ;Will continue to loop if button isn't pressed
        sleep(50)
    WEnd
        While _IsPressed("01", $dll) ;Will continue to loop when button is pressed.
        sleep(50)
    WEnd
    $pos = MouseGetPos()  ;Gets mouse position once button is released
    splashOff()
    iniWrite ( $SettingsFile, 'Poss', 'xpos1', $pos[0] )
EndFunc

Func Ypos()
    SplashTextOn("ypos", "Move your mouse to the furthest top border then click left", -1, 100, -1, -1, 0, "verdana", 18, 450)
    While _IsPressed("01", $dll) =0
        sleep(50)
    WEnd
        While _IsPressed("01", $dll)
        sleep(50)
    WEnd
        $pos = MouseGetPos()
        SplashOff()
        
    iniWrite ( $SettingsFile, 'Poss', 'ypos1', $pos[1] )
EndFunc

Func Xpos2()
    SplashTextOn("xpos2", "Move your mouse to the furthest right border then click left", -1, 100, -1, -1, 0, "verdana", 18, 450)
        While _IsPressed("01", $dll) =0
        sleep(50)
    WEnd
        While _IsPressed("01", $dll)
        sleep(50)
    WEnd
        $pos = MouseGetPos()
        SplashOff()
     iniWrite ( $SettingsFile, 'Poss', 'xpos2', $pos[0] )
EndFunc

Func Ypos2()
    SplashTextOn("ypos2", "Move your mouse to the furthest bottom border then click left", -1, 100, -1, -1, 0, "verdana", 18, 450)
            While _IsPressed("01", $dll) =0
        sleep(50)
    WEnd
        While _IsPressed("01", $dll)
        sleep(50)
    WEnd
        $pos = MouseGetPos()
        SplashOff()
        
    iniWrite ( $SettingsFile, 'Poss', 'ypos2', $pos[1] )
EndFunc
Edited by TurionAltec

Share this post


Link to post
Share on other sites

Ah thanks a million Turion, the script now works flawlessly just as intended, now to add to this, is it possible to get the color in which the mouse is over and save it to the same ini file using the same process?


...will never learn all there is to know about autoit, no worries...i came to the forums :)

Share this post


Link to post
Share on other sites

pixelgetcolor. This will take the coordinates from the previous MouseGetPos(), and save it as a decimal value. You can use Hex() if you want to convert it to a hex value

Func Xpos()
    SplashTextOn("xpos", "Move your mouse to the furthest left border then click left mouse.", -1, 100, -1, -1, 0, "verdana", 18, 450)
    While _IsPressed("01", $dll) =0 ;Will continue to loop if button isn't pressed
        sleep(50)
    WEnd
        While _IsPressed("01", $dll) ;Will continue to loop when button is pressed.
        sleep(50)
    WEnd
    $pos = MouseGetPos()  ;Gets mouse position once button is released
    splashOff()
    iniWrite ( $SettingsFile, 'Poss', 'xpos1', $pos[0] )
    IniWrite($SettingsFile,'Poss','xpos1color', PixelGetColor($pos[0],$pos[1]))
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