Jump to content

reload the same script


Recommended Posts

something like this ?

#include <GuiConstantsEx.au3>

Global $hgui, $GuiFile = @ScriptDir & "\GUISettings.ini"
MainGUI()

Func MainGUI()
    Local $Button1, $GuiPos, $msg
    If FileExists($GuiFile) Then $GuiPos = IniReadSection($GuiFile, "GuiPos")
    If IsArray($GuiPos) then
        $hgui= GUICreate("My GUI Window Title", Default, Default, $GuiPos[1][1], $GuiPos[2][1])
    Else
        $hgui =GUICreate("My GUI Window Title")
    EndIf
    $Button1 = GUICtrlCreateButton("Button 1", 10, 30, 100)

    GUISetState()

    While 1
        $msg = GUIGetMsg()
        Select
            Case $msg = $GUI_EVENT_CLOSE
                _ExitGetPos()
            Case $msg = $GUI_EVENT_PRIMARYDOWN
                GUICtrlSetState($Button1, $GUI_ENABLE)
            Case $msg = $Button1
                GUICtrlSetState($Button1, $GUI_DISABLE)
        EndSelect
        Sleep(50)
    WEnd
EndFunc   ;==>MainGUI

Func _ExitGetPos()
    Local $aPos = WinGetPos($hgui, "")
    IniWrite($GuiFile, "GuiPos", "X-Pos", $aPos[0])
    IniWrite($GuiFile, "GuiPos", "Y-Pos", $aPos[1])
    Exit
EndFunc   ;==>Close

 

Link to comment
Share on other sites

  • 2 weeks later...
#include <misc.au3>
#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
#include <ButtonConstants.au3>
#include <GUIMenu.au3>

Opt("GUIOnEventMode", 1)

Global $gui, $button4, $GuiFile = @ScriptDir & "\GUISettings.ini"

HotKeySet("{ESC}", "caller")

Func _Main()
Local $msg
If FileExists($GuiFile) Then $msg = IniReadSection($GuiFile, "msg")
If IsArray($msg) then
$gui= GUICreate("Tools", 90, 100, $msg[1][1], $msg[2][1], -1, $WS_EX_TOOLWINDOW)
GUISetOnEvent($GUI_EVENT_CLOSE, 'closing')
EndIf
$button4 = GUICtrlCreateButton("tools", 5, 75, 40, 20)
GUICtrlSetOnEvent(-1, "tools")
GUISetState()
While 1
Sleep(10)
WEnd
EndFunc

_Main()

Func closing()
Local $aPos = WinGetPos($gui, "")
IniWrite($GuiFile, "msg", "X-Pos", $aPos[0])
IniWrite($GuiFile, "msg", "Y-Pos", $aPos[1])
Exit
EndFunc

Func tools()

test()
EndFunc

Func test()
   GUICtrlSetState($button4, $GUI_disable)
   HotKeySet("{END}", "Cls0")
HotKeySet("{INS}", "Cls01")
HotKeySet("{HOME}", "Cls")
HotKeySet("{DELETE}", "Play")
GUISetState(@SW_HIDE, $gui); Enable for without _SD
   EndFunc

Func caller()
WinActivate($gui)
GUISetState(@SW_SHOW, $gui)
GUICtrlSetState($button4, $GUI_ENABLE); Enable for without _SD
EndFunc

func cls0()
MouseMove (198,336, 2)
MouseClick("right", 198,336, 1, 1)
MouseMove (56,885,1)
EndFunc

func cls01()
Send ("{ENTER}")
MouseClick("right", 198,336, 1, 1)
Send ("{ENTER}")
MouseMove (56,885,1)
EndFunc

func cls()
MouseClick("right" ,160,669, 1, 1)
MouseMove (56,885,1)
EndFunc

func play()
MouseMove (1090,670,1)
Sleep(234)
MouseClick("right" ,1090,670, 1, 1)
MouseMove (56,885,1)
EndFunc

@Deye

 

my friend, how are you?
help me, I put the ESC key to undo the script button "tools", but the functions still work in the same

Link to comment
Share on other sites

Heya Pedro, 

Keep in mind that If you are using @SW_HIDE <> @SW_SHOW then you don't need to include @SW_DISABLE <> @SW_ENABLE for the GUI, buttons Or any other controls 

See if this example helps:

#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>

Global $hGui, $button1, $hGuiFile = @ScriptDir & "\GUISettings.ini"

Opt("GUIOnEventMode", 1)
HotKeySet("{ESC}", "Caller")

_Main()

Func _Main()
    Local $aGetGuiLastPosition
    If FileExists($hGuiFile) Then $aGetGuiLastPosition = IniReadSection($hGuiFile, "msg")
    If IsArray($aGetGuiLastPosition) Then
        $hGui = GUICreate("Tools", 90, 100, $aGetGuiLastPosition[1][1], $aGetGuiLastPosition[2][1], -1, $WS_EX_TOOLWINDOW)
    Else
        $hGui = GUICreate("Tools", 90, 100, -1, -1, -1, $WS_EX_TOOLWINDOW)
    EndIf
    GUISetOnEvent($GUI_EVENT_CLOSE, '_Exit_Main')
    OnAutoItExitRegister('_On_Exit')

    $button1 = GUICtrlCreateButton("tools", 5, 75, 40, 20)
    GUICtrlSetOnEvent(-1, "_EnableHotkeys")
    GUISetState()

    While 1
        Sleep(10)
    WEnd
EndFunc   ;==>_Main

Func _EnableHotkeys()
    HotKeySet("{END}", "Cls0")
    HotKeySet("{HOME}", "Cls1")
    GUISetState(@SW_HIDE, $hGui)
EndFunc

Func _DisableHotkeys() ; <-------------------------------- (Stop Hotkeys assignment)
    HotKeySet("{END}")
    HotKeySet("{HOME}")
EndFunc

Func Caller()
    _DisableHotkeys() ; <-------------------------------- (Stop Hotkeys assignment)
    WinActivate($hGui)
    GUISetState(@SW_SHOW, $hGui)
EndFunc

Func _Exit_Main()
    Exit
EndFunc

Func _On_Exit()
    Local $aGuiLastPosition = WinGetPos($hGui, "")
    IniWrite($hGuiFile, "msg", "X-Pos", $aGuiLastPosition[0])
    IniWrite($hGuiFile, "msg", "Y-Pos", $aGuiLastPosition[1])
    _DisableHotkeys() ; <-------------------------------- (Stop Hotkeys assignment)
    HotKeySet("{ESC}")
EndFunc

Func cls0()
    Local $aMPos = MouseGetPos()
    MouseMove(56, 885, 5)
    MouseMove($aMPos[0], $aMPos[1], 5)
EndFunc

Func cls1()
    Local $aMPos = MouseGetPos()
    MouseMove(56, 885, 5)
    MouseMove($aMPos[0], $aMPos[1], 5)
EndFunc

 

Edited by Deye
Link to comment
Share on other sites

  • 1 month later...

hi man, how are u? @Deye

help me, fix a problem of last line this script

Func Cls1() dont work

my intention is to make the mouse move from where it is stopped to another area 

#include <misc.au3>
#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
#include <ButtonConstants.au3>
#include <GUIMenu.au3>

Opt("GUIOnEventMode", 1)

Global $gui, $button4, $msg, $GuiFile = @ScriptDir & "\GUIStngs.ini"

HotKeySet("{ESC}", "_caller")

Func _Main()

If FileExists($GuiFile) Then $msg = IniReadSection($GuiFile, "msg")
If IsArray($msg) then
$gui= GUICreate("Tools", 90, 100, $msg[1][1], $msg[2][1], -1, $WS_EX_TOOLWINDOW)
GUISetOnEvent($GUI_EVENT_CLOSE, 'closing')
EndIf
$button4 = GUICtrlCreateButton("tools", 5, 75, 40, 20)
GUICtrlSetOnEvent(-1, "_EnableHotkeys")
GUISetState()

While 1
Sleep(10)
WEnd
EndFunc


_Main()

Func closing()
Local $aPos = WinGetPos($gui, "")
IniWrite($GuiFile, "msg", "X-Pos", $aPos[0])
IniWrite($GuiFile, "msg", "Y-Pos", $aPos[1])
Exit
EndFunc

Func _EnableHotkeys()
;~ HotKeySet("{END}", "Cls0")
HotKeySet("{INS}", "Cls1")
;~ HotKeySet("{HOME}", "Cls")
;~ HotKeySet("{DELETE}", "Play")
HotKeySet("{NUMPAD0}", "MCR")
GUICtrlSetState($button4, $GUI_disable)
EndFunc

Func _DisableHotkeys()
;~     HotKeySet("{END}")
;~     HotKeySet("{HOME}")
    HotKeySet("{NUMPAD0}")
    GUICtrlSetState($button4, $GUI_Enable)
EndFunc

Func _caller()
    _DisableHotkeys()
    WinActivate($gui)
    GUISetState(@SW_SHOW, $gui)
EndFunc

Func MCR()
MouseClick("right")
EndFunc

Func cls1()
      Local $aMPos = MouseGetPos()
      MouseMove($aMPos[100], $aMPos[100], 5)
EndFunc

 

Link to comment
Share on other sites

  • Developers

What are you expecting these 2 lines to do?

Local $aMPos = MouseGetPos()
      MouseMove($aMPos[100], $aMPos[100], 5)

I can only assume you are getting an error on that second line ...right?

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Helloha Pedro, 

here is an example with steps :

1. start the script 
2. Press tools
3. move the mouse to anywhere you want it, then press "{END}" <-- position is saved *  added to save the position on exit

Now when ever you start tools and press "{Home}" the mouse moves to where you last saved it

#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Array.au3>
Global $hGui, $button1, $aMmove, $hGuiFile = @ScriptDir & "\GUISPos.ini"

Opt("GUIOnEventMode", 1)
HotKeySet("{ESC}", "Caller")

_Main()

Func _Main()
    If FileExists($hGuiFile) And loadPositions() Then
    Else
        $hGui = GUICreate("Tools", 90, 100, -1, -1, -1, $WS_EX_TOOLWINDOW)
    EndIf
    GUISetOnEvent($GUI_EVENT_CLOSE, '_Exit_Main')
    OnAutoItExitRegister('_On_Exit')

    $button1 = GUICtrlCreateButton("tools", 5, 75, 40, 20)
    GUICtrlSetOnEvent(-1, "_EnableHotkeys")
    GUISetState()

    While 1
        Sleep(10)
    WEnd
EndFunc   ;==>_Main

Func loadPositions()
    Local $aLastPos = IniReadSection($hGuiFile, "Positions")
    If @error Then Return 0
    Local $aGuiPos = StringSplit($aLastPos[1][1], "|")
    If IsArray($aGuiPos) Then
        $hGui = GUICreate("Tools", 90, 100, $aGuiPos[1], $aGuiPos[2], -1, $WS_EX_TOOLWINDOW)
        If $aLastPos[2][1] Then
            $aMmove = StringSplit(IniRead($hGuiFile, "Positions", "MousePos", ""), "|", 2)
        EndIf
        Return 1
    EndIf
    Return 0
EndFunc   ;==>loadPositions

Func _EnableHotkeys()
    HotKeySet("{END}", "Cls0")
    HotKeySet("{HOME}", "Cls1")
    GUISetState(@SW_HIDE, $hGui)
EndFunc   ;==>_EnableHotkeys

Func _DisableHotkeys()
    HotKeySet("{END}")
    HotKeySet("{HOME}")
EndFunc   ;==>_DisableHotkeys

Func Caller()
    _DisableHotkeys()
    WinActivate($hGui)
    GUISetState(@SW_SHOW, $hGui)
EndFunc   ;==>Caller

Func _Exit_Main()
    Exit
EndFunc   ;==>_Exit_Main

Func _On_Exit()
    Local $aGuiLastPosition = WinGetPos($hGui, "")
    IniWrite($hGuiFile, "Positions", "GuiPos", _ArrayToString($aGuiLastPosition, "|"))
    IniWrite($hGuiFile, "Positions", "MousePos", _ArrayToString($aMmove, "|"))
    _DisableHotkeys()
    HotKeySet("{ESC}")
EndFunc   ;==>_On_Exit

Func cls0()
    $aMmove = MouseGetPos() ;   <-----------------------(Get & Save mouse pointer position)
;~  _ArrayDisplay($aMmove)
EndFunc   ;==>cls0

Func cls1()
    MouseMove($aMmove[0], $aMmove[1], 10) ; <-------( move to saved pointer position)
EndFunc   ;==>cls1

 

Edited by Deye
Link to comment
Share on other sites

  • 2 years later...

Hi all,

Maybe an another way taken from the auto-delete:

#include <File.au3>
$runfile = @ScriptDir & '\run.bat'
FileDelete($runfile)



_FileCreate($runfile)
_FileWriteToLine($runfile, 1, '@echo off' & @CRLF & 'ping localhost -n 1 >nul' & @CRLF & 'start ' & FileGetShortName(@ScriptFullPath), False, True)
Run($runfile, @WorkingDir, @SW_HIDE)
Exit

Be carfull if you run this script alone, it will loop forever !!!

 

Have fun!

 

C.

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...