I have a thousands mini tools, I am trying to create a menu by using Autuit. I have to define thousand functions and case and variable how i can make it easy.
here is my code how can use loop for select case and run soft.exe
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
$Form1 = GUICreate("MainMenu", 615, 437, 192, 124)
$Soft1 = GUICtrlCreateButton("Button1", -8, 0, 75, 25)
$Soft2 = GUICtrlCreateButton("Button2", -18, 10, 75, 25)
$Soft3 = GUICtrlCreateButton("Button3", -28, 20, 75, 25)
$Soft4 = GUICtrlCreateButton("Button4", -38, 30, 75, 25)
$Soft5 = GUICtrlCreateButton("Button5", -48, 40, 75, 25)
$Soft6 = GUICtrlCreateButton("Button6", -58, 50, 75, 25)
GUISetState(#SW_SHOW)
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Soft1
Startsoft1()
Case $Soft2
Startsoft2()
Case $Soft3
Startsoft3()
Case $Soft4
Startsoft4()
Case $Soft5
Startsoft5()
Case $Soft6
Startsoft6()
EndSwitch
WEnd
Func Startsoft1()
Run('Soft1.exe')
EndFunc
Func Startsoft2()
Run('Soft2.exe')
EndFunc
Func Startsoft3()
Run('Soft3.exe')
EndFunc
Func Startsoft4()
Run('Soft4.exe')
EndFunc
Func Startsoft5()
Run('Soft5.exe')
EndFunc
iam new in programing there for learning new things
Try something like this as a good starting point.
Put the names and pathes in the strings of the method StringSplit.
The GUI buttons are automatically placed in a new line if the button reaches the GUI width end.
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
main()
Func main()
Local $gui_width = #DesktopWidth -100, $gui_height = #DesktopHeight - 80
Local $Form1 = GUICreate("MainMenu", $gui_width, $gui_height, 50, 10)
Local $exesName_A = StringSplit('a.exe,b.exe,c.exe,d.exe,e.exe,f.exe,g.exe,h.exe,i.exe,j.exe,k.exe,l.exe,m.exe,n.exe,o.exe,a.exe,b.exe,c.exe,d.exe,e.exe,f.exe,g.exe,h.exe,i.exe,j.exe,k.exe,l.exe,m.exe,n.exe,o.exe', ',', 2)
Local $exesPath_A = StringSplit('a.exe,b.exe,c.exe,d.exe,e.exe,f.exe,g.exe,h.exe,i.exe,j.exe,k.exe,l.exe,m.exe,n.exe,o.exe,a.exe,b.exe,c.exe,d.exe,e.exe,f.exe,g.exe,h.exe,i.exe,j.exe,k.exe,l.exe,m.exe,n.exe,o.exe', ',', 2)
Local $height = 45, $width = 125, $y = 0, $x = 0
Local $button_A[UBound($exesName_A)]
For $i = 0 To UBound($exesName_A) - 1
If ((8 + ($x + 1) * $width) > $gui_width) Then
$y += 1
$x = 0
EndIf
$button_A[$i] = GUICtrlCreateButton($exesName_A[$i], 8 + $x * $width, 10 + $y * $height, 75, $height)
GUICtrlSetImage(-1, "shell32.dll", 22+ $i)
$x += 1
Next
GUISetState(#SW_SHOW)
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
EndSwitch
; scan all buttons to check if one was pressed
For $i = 0 To UBound($button_A) - 1
If $nMsg = $button_A[$i] Then
ConsoleWrite('Now run the exe' & $exesPath_A[$i] & #CRLF)
;~ ShellExecute($exesPath_A[$i], '') ; uncomment this to run the exe
EndIf
Next
WEnd
EndFunc ;==>main
Related
How to get an alert once on a supertrend trend,I think with while i can solve(but my knowledge is not enough),maybe is another way to solve my problem.
I need to skip the first signal(on down/up trend) and enter the second alert, and this signal alert one time per supertrend trend.
I describe signals below in the code.
//#version=5
indicator("My-Supertrend", overlay=true, timeframe="", timeframe_gaps=true)
atrPeriod = input(13, "ATR Length")
atrPeriod2 = input(21, "ATR Length2")
factor = input.float(3.0, "Factor", step = 0.01)
factor2 = input.float(7.0, "Factor2", step = 0.01)
[supertrend, direction] = ta.supertrend(factor, atrPeriod)
[supertrend2, direction2] = ta.supertrend(factor2, atrPeriod2)
//ST 1
bodyMiddle = plot((open + close) / 2, display=display.none)
upTrend = plot(direction < 0 ? supertrend : na, "Up Trend", color = #00cf42, style=plot.style_linebr,linewidth=1)
downTrend = plot(direction < 0? na : supertrend, "Down Trend", color = #bb2c01, style=plot.style_linebr,linewidth=1)
//ST 2
bodyMiddle2 = plot((open + close) / 2, display=display.none)
upTrend2 = plot(direction2 < 0 ? supertrend2 : na, "Up Trend", color = #00cf42, style=plot.style_linebr,linewidth=3)
downTrend2 = plot(direction2 < 0? na : supertrend2, "Down Trend", color = #bb2c01, style=plot.style_linebr,linewidth=3)
//ST1 color
fill(bodyMiddle, upTrend, color.new(#95bd06, 80), fillgaps=false)
fill(bodyMiddle, downTrend, color.new(#0692bd, 80), fillgaps=false)
//ST2 color
fill(bodyMiddle2, upTrend2, color.new(#5abd13, 70), fillgaps=false)
fill(bodyMiddle2, downTrend2, color.new(#bd3006,70), fillgaps=false)
//Logic
down_upTrend=direction>0 and direction2<0 and direction[1]<0
up_upTrend=direction<0 and direction2<0 and direction[1]>0
up_downTrend=direction<0 and direction2>0 and direction[1]>0
down_downTrend=direction>0 and direction2>0 and direction[1]<0
//For short
while direction2>0
up_downTrend
continue
down_downTrend
break
//For Long
while direction2<0
down_upTrend
continue
up_upTrend
break
plotshape(up_upTrend,style=shape.triangleup,location=location.belowbar,size=size.normal,color=color.rgb(27, 182, 27))
plotshape(up_downTrend,style=shape.triangleup,location=location.belowbar,size=size.normal,color=color.rgb(20, 112, 20))
plotshape(down_upTrend,style=shape.triangledown,location=location.abovebar,size=size.normal,color=color.rgb(255, 0, 0))
plotshape(down_downTrend,style=shape.triangledown,location=location.abovebar,size=size.normal,color=color.rgb(141, 21, 21))
alertcondition(up_upTrend or down_downTrend,"Long/Short","Signal")
I try to solve with while loop(and i describe my logic in while loop),but while dont work like I think.
I have an mp3.txt file which contains URLs to download. How do I read the contents to then download the URLs? I tried this but it's not working:
Func _downloader($link)
Local $dwnarrayread[3] = [IniRead(#ScriptDir & "\mp3.txt", "file_links", "link_1", Default), IniRead(#ScriptDir & "\mp3-2.txt", "file_links", "link_2", Default), IniRead(#ScriptDir & "\mp3-3.txt", "file_links", "link_3", Default)]
$dwnlink = InetGet($dwnarrayread[$link], #ScriptDir & "PSU-04.mp3", 1, 1)
Do
Sleep(50)
$prc = Round(InetGetInfo($dwnlink, 0) / (InetGetInfo($dwnlink, 1)) * 100)
GUICtrlSetData($progressbar1, $prc)
Until InetGetInfo($dwnlink, $INET_DOWNLOADCOMPLETE)
EndFunc
mp3.txt file :
[files_links]
link_1=https://ftp.psu.ac.th/pub/demo/mp3/PSU-04.mp3
link_2=http://somesite.com/files/file2.zip
link_3=http://somesite.com/files/file3.zip
How do I read the contents to then download the URLs?
Example (as per additional requirement):
_Download('mp3.txt', 'files_links', #DesktopDir & '\')
Func _Download(Const $sFileIni, Const $sSection, Const $sDest)
Local Const $aFile = IniReadSection($sFileIni, $sSection)
For $i1 = 1 To $aFile[0][0]
InetGet($aFile[$i1][1], $sDest & StringTrimLeft($aFile[$i1][1], StringInStr($aFile[$i1][1], '/', 0, -1)))
Next
EndFunc
Example as per GUICtrlSetData() -attempt:
#include <AutoItConstants.au3>
#include <InetConstants.au3>
#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>
_Download('mp3.txt', 'files_links', #DesktopDir & '\')
Func _Download(Const $sFileIni, Const $sSection, Const $sDest)
Local Const $aFile = IniReadSection($sFileIni, $sSection)
Local $aDownload[$aFile[0][0] + 1]
$aDownload[0] = $aFile[0][0]
For $i1 = 1 To $aFile[0][0]
$aDownload[$i1] = InetGet($aFile[$i1][1], $sDest & StringTrimLeft($aFile[$i1][1], StringInStr($aFile[$i1][1], '/', 0, -1)), $INET_FORCERELOAD, $INET_DOWNLOADBACKGROUND)
Next
Local Const $iWidth = 400, _
$iHeight = 20
Local $hWnd = GUICreate(#ScriptName, $iWidth, $iHeight * $aDownload[0])
Local $aHnd[$aDownload[0] + 1]
For $i1 = 1 To $aDownload[0]
$aHnd[$i1] = GUICtrlCreateProgress(0, ($i1 - 1) * $iHeight, $iWidth, $iHeight)
GUICtrlSetTip($aHnd[$i1], $aFile[$i1][1])
Next
GUISetState(#SW_SHOW, $hWnd)
Local $aInfo
While Not (GUIGetMsg() = $GUI_EVENT_CLOSE)
For $i1 = 1 To $aDownload[0]
$aInfo = InetGetInfo($aDownload[$i1])
GUICtrlSetData($aHnd[$i1], ($aInfo[$INET_DOWNLOADCOMPLETE] Or $aInfo[$INET_DOWNLOADSUCCESS]) ? 100 : $aInfo[$INET_DOWNLOADSIZE] / $aInfo[$INET_DOWNLOADREAD])
Next
If InetGetInfo() Then ContinueLoop
MsgBox($MB_OK, #ScriptName, 'No more running downloads.', 0, $hWnd)
ExitLoop
WEnd
For $i1 = 1 To $aDownload[0]
InetClose($aDownload[$i1])
Next
EndFunc
#include <GUIConstantsEx.au3>
#Include <GuiComboBox.au3>
#include <GuiComboBoxEx.au3>
; Create GUI
$hGUI = GUICreate("Test", 500, 500)
Global $hCombo = GUICtrlCreateCombo("", 10, 10, 250, 20)
GUICtrlSetData($hCombo, "Atchu | Muthu | Ponreegan | Vijay | Vasu", "Vasu")
$hGetButton = GUICtrlCreateButton("Get", 270, 10, 30, 20)
Global $temp = " "
While 1
Switch GUIGetMsg()
Case $GUI_EVENT_CLOSE
Exit
Case $hAddButton
$temp = _GUICtrlComboBoxEx_GetEditText($hCombo)
MsgBox($MB_SYSTEMMODAL, "", "You chose: " & $temp)
Exit
EndSwitch
WEnd
There are few names added to combo box, on clicking "Get button", it is not returning string. Any idea?
Your code does not even run. There are two issues:
The first is that you use $hGetButton when creating the button, but $hAddButton when waiting for a GUI message in your loop. This is what causes your code to fail to run.
The second issue is that you are using the wrong function to read the combobox data. You should use GUICtrlRead
Fixing these issues makes the code work:
#include <GUIConstantsEx.au3>
#Include <GuiComboBox.au3>
#include <GuiComboBoxEx.au3>
; Create GUI
$hGUI = GUICreate("Test", 500, 500)
Global $hCombo = GUICtrlCreateCombo("", 10, 10, 250, 20)
GUICtrlSetData($hCombo, "Atchu | Muthu | Ponreegan | Vijay | Vasu", "Vasu")
$hGetButton = GUICtrlCreateButton("Get", 270, 10, 30, 20)
Global $temp = " "
GUISetState ( #SW_SHOW , $hGUI )
While 1
Switch GUIGetMsg()
Case $GUI_EVENT_CLOSE
Exit
Case $hGetButton
$temp = GUICtrlRead($hCombo)
MsgBox($MB_SYSTEMMODAL, "", "You chose: " & $temp)
Exit
EndSwitch
WEnd
The objective is to create timers for League of Legends. It has jungle camps; each one respawns a certain time after killing it.
For this I want to activate the same function for multiple timers at the same time. If I kill blue buff and wolves at the same time I want timers for both of them (click the blue golem's button for my wolves to get the same timer).
I haven't implemented the wolves button but do have a start button. Clicking the blue button starts my timer, but following it up with a click on start game button just queues it until after first timer finishes.
I looked into the wiki page. But I don't want to stop the running timer; I want to run another at the same time. Are there coding errors, better ways of doing things, etc.? Here is my code:
#include <GUIConstantsEx.au3>
#include <ButtonConstants.au3>
#include <Timers.au3>
;==> Set our $font variable
Global $font
$font = "Arial Black"
;==> Create our Graphic User Interface
Opt("GUIOnEventMode", 1) ; Change to OnEvent mode
$mainwindow = GUICreate("Jungle Timers Deluxe", 200, 400)
GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked")
$startbutton = GUICtrlCreateButton("Start Game", 50, 10, 70)
$ybluebuff = GUICtrlCreateButton("Ancient Golem (Blue)", 10, 40, 50, 50, $BS_MULTILINE)
$yredbuff = GUICtrlCreateButton("Lizard Elder (Red)", 10, 110, 50, 50, $BS_MULTILINE)
$ywraiths = GUICtrlCreateButton("Lizard Elder (Red)", 10, 180, 50, 50, $BS_MULTILINE)
$ywolves = GUICtrlCreateButton("Lizard Elder (Red)", 10, 250, 50, 50, $BS_MULTILINE)
$ydgolems = GUICtrlCreateButton("Lizard Elder (Red)", 10, 320, 50, 50, $BS_MULTILINE)
$ebluebuff = GUICtrlCreateButton("Ancient Golem (Blue)", 100, 40, 50, 50, $BS_MULTILINE)
$eredbuff = GUICtrlCreateButton("Lizard Elder (Red)", 100, 110, 50, 50, $BS_MULTILINE)
$ewraiths = GUICtrlCreateButton("Lizard Elder (Red)", 100, 180, 50, 50, $BS_MULTILINE)
$ewolves = GUICtrlCreateButton("Lizard Elder (Red)", 100, 250, 50, 50, $BS_MULTILINE)
$edgolems = GUICtrlCreateButton("Lizard Elder (Red)", 100, 320, 50, 50, $BS_MULTILINE)
;==> Create our events
GUICtrlSetOnEvent($startbutton, "StartGame")
GUICtrlSetOnEvent($ybluebuff, "yBlueBuff")
;==> Display our Graphic User Interface.
GUISetState(#SW_SHOW)
While 1
Sleep(1000) ; Idle around
WEnd
Func yBlueBuff()
Dim $bluetimer = 10
$i = 1
$ybb = GUICtrlCreateLabel("Your Blue Buff:", 10, 40)
GUICtrlDelete($ybluebuff)
$ybblabel = GUICtrlCreateLabel($i, 15, 60, 50, 40)
While $i <= $bluetimer
GUICtrlDelete($ybblabel)
If $i >= 5 Then
$ybblabel = GUICtrlCreateLabel($i, 15, 60, 50, 40)
GUICtrlSetFont(-1, 22, 500, $font)
GUICtrlSetBkColor($ybblabel, 0xFFCCCC)
$i = $i + 1
ElseIf $i < 5 Then
$ybblabel = GUICtrlCreateLabel($i, 15, 60, 50, 40)
GUICtrlSetFont(-1, 22, 500, $font)
$i = $i + 1
EndIf
Sleep(1000)
WEnd
GUICtrlDelete($ybblabel)
GUICtrlDelete($ybb)
$ybluebuff = GUICtrlCreateButton("Ancient Golem (Blue)", 10, 40, 50, 50, $BS_MULTILINE)
EndFunc ;==>yBlueBuff
Func StartGame()
; Activate your League Window
WinActivate("[CLASS:Notepad]")
; Wait for the Notepad become active - it is titled "Untitled - Notepad" on English systems
WinWaitActive("[CLASS:Notepad]")
; Now that the Notepad window is active type some text
Send("{ENTER}Baron spawns in 15, Dragon spawns at 2:30{ENTER}")
Sleep(500)
Send("{ENTER}Wraiths/Wolves/Double Golems spawn at 1:40. Red & Blue spawn at 1:55{ENTER}")
Sleep(500)
EndFunc ;==>StartGame
Func CLOSEClicked()
;Note: at this point #GUI_CTRLID would equal $GUI_EVENT_CLOSE,
;and #GUI_WINHANDLE would equal $mainwindow
MsgBox(0, "GUI Event", "Thanks for using Jungle Timers Deluxe!")
Exit
EndFunc ;==>CLOSEClicked
; Finished!
I built this off the Notepad example tutorials and use Notepad because it is easier to debug.
AutoIt does not support running two functions simultaneously, otherwise known as multithreading.
Here is their explanation: AutoItNotOnToDoList
In order for your program to work, you would have to be able to constantly monitor whether or not a button is being pressed and at the same time execute the functions that are called by the buttons.
Although it is not technically mulithreading, a workaround for this problem is running multiple scripts at the same time.
Are there ... better ways of doing things, etc.?
Example demonstrating multiple timers (and responsive GUI) :
#include <GUIConstantsEx.au3>; $GUI_EVENT_CLOSE
#include <Timers.au3>
Global Enum $TMR_NAME, _
$TMR_TIME, _
$TMR_STAMP, _
$TMR_STATE, _
$TMR_PROGR, _
$TMR_BTN, _
$TMR__ENUM
Global $g_aTimer[3][$TMR__ENUM]
$g_aTimer[0][$TMR_NAME] = 'Timer A'
$g_aTimer[0][$TMR_TIME] = 60
$g_aTimer[1][$TMR_NAME] = 'Timer B'
$g_aTimer[1][$TMR_TIME] = 30
$g_aTimer[2][$TMR_NAME] = 'Timer C'
$g_aTimer[2][$TMR_TIME] = 10
Main()
Func Main()
Local $iMsg = 0
Local $hGui
GuiMain($hGui, 400, 25)
While True
$iMsg = GUIGetMsg()
Switch $iMsg
Case $GUI_EVENT_CLOSE
ExitLoop
Case Else
ButtonCheck($iMsg)
EndSwitch
TimerUpdate()
WEnd
GUIDelete($hGui)
Exit
EndFunc
Func GuiMain(ByRef $hGui, Const $iWidth, Const $iHeightTimer)
Local Const $iAmount = UBound($g_aTimer)
$hGui = GUICreate(#ScriptName, $iWidth, $iHeightTimer * 2 * $iAmount)
For $i1 = 0 To $iAmount - 1
$g_aTimer[$i1][$TMR_BTN] = GUICtrlCreateButton($g_aTimer[$i1][$TMR_NAME], 0, $i1 * ($iHeightTimer * 2), $iWidth / 2, $iHeightTimer)
$g_aTimer[$i1][$TMR_PROGR] = GUICtrlCreateProgress(0, $iHeightTimer + $i1 * ($iHeightTimer * 2), $iWidth, $iHeightTimer)
Next
GUISetState(#SW_SHOW, $hGui)
EndFunc
Func ButtonCheck(Const $iMsg)
For $i1 = 0 To UBound($g_aTimer) - 1
If $iMsg = $g_aTimer[$i1][$TMR_BTN] Then
$g_aTimer[$i1][$TMR_STATE] = True
$g_aTimer[$i1][$TMR_STAMP] = _Timer_Init()
ExitLoop
EndIf
Next
EndFunc
Func TimerUpdate()
Local $nDiff
For $i1 = 0 To UBound($g_aTimer) - 1
If Not $g_aTimer[$i1][$TMR_STATE] Then ContinueLoop
$nDiff = _Timer_Diff($g_aTimer[$i1][$TMR_STAMP]) / ($g_aTimer[$i1][$TMR_TIME] * 1000) * 100
If $nDiff > 100 Then
$nDiff = 100
$g_aTimer[$i1][$TMR_STATE] = False
EndIf
GUICtrlSetData($g_aTimer[$i1][$TMR_PROGR], $nDiff)
Next
EndFunc
I'm trying to do the following, and can't figure out how exactly do It without crashing or infinite looping:
I have to create a queue in which I have to distribute different tasks a different number of times each, alternatively with this kind of info:
Task X: [NextOne,LastOne]
Task 1: [30,32]
Task 2: [76,81]
Task 3: [2,2]
Task 4: [5,8]
Meaning that "Task X" will be made "LastOne - NextOne" times, and if both are equal, it won't be enqueued, and they enter the queue in X order.
With this example, the queue should look like:
FIRST
Task1[30]
Task2[76]
Task4[5]
Task1[31]
Task2[77]
Task4[6]
Task1[32]
Task2[78]
Task4[7]
Task2[79]
Task4[8]
Task2[80]
Task2[81]
LAST
It's not a language issue, it's more of an algorithm issue I have here. Using PHP I've made the following:
$tasks = array(
'Task1' => array(30,32),
'Task2' => array(76,81),
'Task3' => array(2,2),
'Task4' => array(5,8)
);
$aux = array();
$i=0;
foreach($tasks as $s=>$n) {
$aux[$i]['task'] = $s;
$aux[$i]['times'] = $n[1]-$n[0];
$aux[$i]['first'] = $n[0];
$i++;
}
But as you imagine this actually does nothing, just change the shape of the information. I'm really stuck here I don't know why, this actually shouldn't be hard to figure out. I'd appreciate any help.
In python (I may be misinterpreting your "it's not a language issue" comment - forgive me):
tasks = [
("Task1", 30, 32),
("Task2", 76, 81),
("Task3", 2, 2),
("Task4", 5, 8) ]
while not tasks == []:
# Pop first task off the current list
(n, s, e) = tasks[0]
tasks = tasks[1:]
print n, s
if s != e:
tasks.append( (n, s+1, e) )
Sorry it's not in php - it's not my forte, but perhaps this'll help? Output:
Task1 30
Task2 76
Task3 2
Task4 5
Task1 31
Task2 77
Task4 6
Task1 32
Task2 78
Task4 7
Task2 79
Task4 8
Task2 80
Task2 81
I guess you can use $s as a key for the hash(or array equivalent) and just increase the value by 1 whenever it encounters the element with the same key. The default value would be 0 in this case.
For example,
Task1 => array(30,32)
will be come in order like
Task1[30] (default value to 0)
...
...
Task1[31] (add 1 which becomes 1)
...
Task1[32] (add 1 which becomes 2)
This means that Task1 has appeared 3 times overall, and the final times value should be 2.
I think you can use array_key_exists helper function to check if certain task had appeared previously.
In C#
The result is as you wish.
I added a number as a flag: 1 = Not to be enqueued, 2 = Last record of the task.
Not efficient but works!
private static void Main()
{
var tasks = new Dictionary<string, int[]>
{
{"Task1", new[] {30, 32, 0}},
{"Task2", new[] {76, 81, 0}},
{"Task3", new[] {2, 2, 0}},
{"Task4", new[] {5, 8, 0}}
};
int loopCounter = 0;
Console.WriteLine("FIRST");
while (loopCounter < tasks.Count)
{
foreach (var task in tasks)
{
if (task.Value[0] == task.Value[1])
{
if (task.Value[2] == 2)
{
loopCounter++;
Console.WriteLine(task.Key + "[" + task.Value[0] + "]");
task.Value[2] = 1;
}
else if (task.Value[2] == 0)
{
loopCounter++;
task.Value[2] = 1;
}
}
else
{
Console.WriteLine(task.Key + "[" + task.Value[0] + "]");
task.Value[0]++;
if (task.Value[0] == task.Value[1])
task.Value[2] = 2;
}
}
}
Console.WriteLine("LAST");
Console.ReadLine();
}
Output:
FIRST
Task1[30]
Task2[76]
Task4[5]
Task1[31]
Task2[77]
Task4[6]
Task1[32]
Task2[78]
Task4[7]
Task2[79]
Task4[8]
Task2[80]
Task2[81]
LAST
Hope this helps.