Jump to content

Custom Input box and global variable


RongYao
 Share

Go to solution Solved by RongYao,

Recommended Posts

Hello guys, i'm new to the autoit, previously used batch to automate things but decide to give autoit a try since i see many cool things can be done with it and it is not as hard as it looks thought.

I was looking for a program which would allow me to autosave in certain drawing programs and i found this.

Photoshop Autosave
'?do=embed' frameborder='0' data-embedContent>>

So, credits to the guy that made it, it is amazing.

I took the script and tried to add input box so people to be able to change the period for autosave, also removed the variables and made script read from file, so people to not need to recompile the whole script again and again, just to use it.
 

#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>
#include <WindowsConstants.au3>
#include <File.au3>

Opt('TrayMenuMode', 1)

Global $sminutess = 10
Global $sminutess = InputBox("Time to autosave?","Enter time in minutes to run autosave!" & @LF & "From 1 minute to 1440 minutes (1 day)!","10","","300","170")
If $sminutess = 0 Then Global $sminutess = 10
If $sminutess > 1440 Then Global $sminutess = 10
    If @Error = 1 Then Exit
Global $interval = (1000 * ($sminutess * 60))

Global $Exit = TrayCreateItem('Exit')
Global $start = 0

While True
    Global $Msg = TrayGetMsg()

    Switch $Msg
        Case $Exit
            ExitLoop
    EndSwitch

    Global $delta = TimerDiff($start)
    Global $remaining = Round(($interval - $delta) / 1000)
    TraySetToolTip('Next autosave in ' & $remaining & ' seconds')

    If ($delta > $interval) Then
        Autosave()
        $start = TimerInit()
    EndIf
WEnd

Func Autosave()
$titlefile = "autosave.txt"
FileOpen($titlefile, 0)
For $i = 1 to _FileCountLines($titlefile)
    If WinActive(FileReadLine($titlefile, $i)) Then
        Send('^s')
   endif
Next
FileClose($titlefile)
EndFunc

This script works without an issue, true it does not check if file exists or have rights to be read, but it works if autosave.txt is in the same directory and has lines inside.

The only problem is the input box for me, i wanted to use custom one and i can't figure out how to do it, i need to rewrite the whole thing, still thats my first attempt to work with autoit and it does not goes well.

Then i've tried to find good example of inputbox with updown controls limited to use only digits and i found one.


Then I edited it to suit my preferences before merge it with the script above and replace the inputbox i use there.

 

#include "GUIConstants.au3"

$title = GUICreate("My GUI UpDown",320,150,-1,-1, $WS_SIZEBOX)

$input = GUICtrlCreateInput ("10",10,10, 50, 20, $ES_NUMBER)
$updown = GUICtrlCreateUpdown($input)
GUICtrlSetLimit($updown,1440,0)
$old = 10
; Attempt to resize input control
GUICtrlSetPos($input, 10,10, 300, 50 )

GUISetState ()

; Run the GUI until the dialog is closed

While 1
    $msg = GUIGetMsg()
    If $old <> Int(GUICtrlRead($input)) Then
        If $old < Int(GUICtrlRead($input)) Then; up
            $old = ((Int(GUICtrlRead($input)) - $old) * 1) + $old
            If $old > 1440 Then $old = 0
            GUICtrlSetData($input,$old)
        Else
            $old = (($old - Int(GUICtrlRead($input))) * -1) + $old
            If $old < 0 Then $old = 0
            GUICtrlSetData($input,$old)

        EndIf
    EndIf

    If $msg = $GUI_EVENT_CLOSE Then GUIDelete($title)

Wend

Thing is i dont know how to replace
 

Global $sminutess = 10
Global $sminutess = InputBox("Time to autosave?","Enter time in minutes to run autosave!" & @LF & "From 1 minute to 1440 minutes (1 day)!","10","","300","170")
If $sminutess = 0 Then Global $sminutess = 10
If $sminutess > 1440 Then Global $sminutess = 10
    If @Error = 1 Then Exit

from the first script with the one above, i'm trying to set global interval value before gui deletion but it always ends up returns 0 and it not work as expected.

Link to comment
Share on other sites

  • Solution

Fixed it!

 

#include <GUIConstants.au3>
#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>
#include <WindowsConstants.au3>
#include <File.au3>

Opt('TrayMenuMode', 1)

Global $Exit = TrayCreateItem('Exit')
Global $start = 0

Global $title = GUICreate("Time to autosave?",320,170,-1,-1)
Global $text = GUICtrlCreateLabel("Enter time in minutes to run autosave!" & @LF & "From 1 minute to 1440 minutes (1 day)!" & @LF & "Enter a time and press (X) to close the window." & @LF & "You may quit with clicking Exit from the quicktray.","", -1, -1)
Global $inputbox = GUICtrlCreateInput("10",10,10, 50, 20, $ES_NUMBER)
Global $updown = GUICtrlCreateUpdown($inputbox)
GUICtrlSetLimit($updown,1440,0)
Global $old = 10
; Attempt to resize input control
GUICtrlSetPos($inputbox, 10,10, 300, 50 )
GUICtrlSetPos($text, 10,70, 300, 70 )

GUISetState(@SW_SHOW)

; Run the GUI until the dialog is closed

While 1
    $input = GUICtrlRead($inputbox)
    $msg = GUIGetMsg()
    If $old <> Int(GUICtrlRead($inputbox)) Then
        If $old < Int(GUICtrlRead($inputbox)) Then; up
            $old = ((Int(GUICtrlRead($inputbox)) - $old) * 1) + $old
            If $old > 1440 Then $old = 0
            GUICtrlSetData($inputbox,$old)
        Else
            $old = (($old - Int(GUICtrlRead($inputbox))) * -1) + $old
            If $old < 0 Then $old = 0
            GUICtrlSetData($inputbox,$old)
        EndIf
     EndIf

   If $msg = $GUI_EVENT_CLOSE Then GUIDelete($title)
   If $msg = $GUI_EVENT_CLOSE Then Exitloop

WEnd

Global $interval = (1000 * ($input * 60))

While True
    Global $Msg = TrayGetMsg()

    Switch $Msg
        Case $Exit
            ExitLoop
    EndSwitch

    Global $delta = TimerDiff($start)
    Global $remaining = Round(($interval - $delta) / 1000)
    TraySetToolTip('Next autosave in ' & $remaining & ' seconds')

    If ($delta > $interval) Then
        Autosave()
        $start = TimerInit()
     EndIf

WEnd

Func Autosave()
$titlefile = "autosave.txt"
FileOpen($titlefile, 0)
For $i = 1 to _FileCountLines($titlefile)
    If WinActive(FileReadLine($titlefile, $i)) Then
        Send('^s')
   endif
Next
FileClose($titlefile)
EndFunc
Edited by RongYao
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...