I know the title sounds confusing, but let's say I have an edit control, and a Treeview control, and a button, in the edit I type in something like "TV_Add("Fruits"), and it adds into the TreeView, a branch called Fruits, like it deconstructs the text from the edit control, and performs the command/function with the given parameters, inside its own script, not into another script, so I can't append that text into another file, because it would do it to another script, not the actual one, and I wouldn't want to have to reload the current script with the text added into it
let me rephrase my words:
basically something like what Scratch does, real-time editing without reloading the script, I type in TV_Add("Fruits") and it adds in a branch called Fruits, automatically, deconstructing the command and its parameters into something it will perform, I think we could do something similar to how the AutoHotkey code deconstructs the commands and its parameters, can this be done?
tl;dr: is it possible to deconstruct a command entered into an edit control, and perform that command, without appending the command into another script somewhere else, but on the same script/gui the edit control is on
Deconstructing and performing a written command into its own script
-
- Posts: 40
- Joined: 12 Jun 2021, 15:28
Re: Deconstructing and performing a written command into its own script
This does it.
viewtopic.php?f=6&t=62550
and so does this simpler example.
This is the part from it that runs the code.
viewtopic.php?f=6&t=62550
and so does this simpler example.
Code: Select all
#SingleInstance, Force
#NoEnv
SetBatchLines, -1
Main.Setup()
return
HBMainGuiClose:
ExitApp
class Main {
;Written By: Hellbent
;Date: Sept 11th , 2021
SetUp(){
This.ParamCountList := { New: { count: 3 , prototype: "GuiHwnd := Gui.New( Options , Name )" , Defaults: { Param1: "GuiHwnd" , Param2: "+AlwaysOnTop" } }
, Show: { count: 3 , prototype: "Gui.Show( Options , Title , Name )" , Defaults: { Param1: "AutoSize NA" } }
, Hide: { count: 1 , prototype: "Gui.Hide( Name )" } ;No Defaults
, Enable: { count: 1 , prototype: "Gui.Enable( Name )" } ;No Defaults
, Disable: { count: 1 , prototype: "Gui.Disable( Name )" } ;No Defaults
, Destroy: { count: 1 , prototype: "Gui.Destroy( Name )" } ;No Defaults
, Get: { count: 4 , prototype: "Output := Gui.Get( Control , SubCommand , Name )" , Defaults: { Param1: "Output" } }
, Set: { count: 4 , prototype: "Gui.Set( Control , Value , SubCommand , Name )" } ;No Defaults
, Margin: { count: 3 , prototype: "Gui.Margin( X , Y , Name )" , Defaults: { Param1: "10" , Param2: "10" } }
, Color: { count: 3 , prototype: "Gui.Color( Color1 , Color2 , Name )" , Defaults: { Param1: "F0F0F0" , Param2: "FFFFFF" } }
, WindowPosition: { count: 2 , prototype: "WindowPosition := Gui.WindowPosition( HWND )" , Defaults: { Param1: "WindowPosition" , Param2: "GuiHwnd" } }
, ControlPosition: { count: 3 , prototype: "ControlPosition := Gui.ControlPosition( Control , Name )" , Defaults: { Param1: "ControlPosition" } }
, Add: { count: 5 , prototype: "ControlName := Gui.Add( Type , Options , Display , Name )" , Defaults: { Param1: "ControlName" , Param2: "Button" , Parma3: "xm ym" , Param4: "Button" } }
, Font: { count: 3 , prototype: "Gui.Font( Font , Options , Name )" , Defaults: { Param1: "Segoe UI" , Param2: "s8 cBlack q5" } }
, Options: { count: 2 , prototype: "Gui.Options( Options , Name )" , Defaults: { Param1: "+Resize" } }
, Bind: { count: 4 , prototype: "Gui.Bind( Control , Method , BoundObject , Name )" } } ;No Defaults
This.Controls := {}
This.Handles := []
This.GuiName := "Gui1"
This.Tog := 0
This.GuiHwnd := Gui.New( "+AlwaysOnTop +Delimiter~ " , "HBMain" )
Gui.Margin( 10 , 10 , "HBMain" )
Gui.Color( "F0F0F0" , "" , "HBMain" )
;New Button
This.Controls.NewButton := Gui.Add( "Button" , "xm ym w100 r1" , "New Window" , "HBMain" )
This._Bind( This.Controls.NewButton , "_AddNewWindow" )
;AddControl Button
This.Controls.AddControlButton := Gui.Add( "Button" , "x+10 ym w100 r1" , "Add Control" , "HBMain" )
This._Bind( This.Controls.AddControlButton , "_AddAddControl" )
;Show Button
This.Controls.ShowButton := Gui.Add( "Button" , "x+10 ym w100 r1" , "Show Window" , "HBMain" )
This._Bind( This.Controls.ShowButton , "_AddShowWindow" )
;Method DDL
This.Controls.MethodDDL := Gui.Add( "DDL" , "xm w150 r20" , "New~~Show~Hide~Enable~Disable~Destroy~Get~Set~Margin~Color~WindowPosition~ControlPosition~Add~Font~Options~Bind~" , "HBMain" )
;Add Button
This.Controls.AddButton := Gui.Add( "Button" , "x+10 w70 r1" , "Add" , "HBMain" )
This._Bind( This.Controls.AddButton , "_AddElement" )
;ElementListBox
This.Controls.ElementListBox := Gui.Add( "ListBox" , " xm w250 r25 -E0x200 AltSubmit" , , "HBMain" )
This._Bind( This.Controls.ElementListBox , "_SelectElement" )
;Lock CheckBox
This.Controls.LockCheckBox := Gui.Add( "CheckBox" , "x+10 section" , "Unlock" , "HBMain" )
This._Bind( This.Controls.LockCheckBox , "_ToggleLock" )
;Delete Button
This.Controls.RemoveButton := Gui.Add( "Button" , "xs w70 Disabled" , "Remove" , "HBMain" )
This._Bind( This.Controls.RemoveButton , "_RemoveElement" )
;Copy Button
This.Controls.CopyButton := Gui.Add( "Button" , "xs y+5 w70" , "Copy" , "HBMain" )
This._Bind( This.Controls.CopyButton , "_CopyElement" )
;Up Button
This.Controls.UpButton := Gui.Add( "Button" , "xs y+5 w70" , "Up" , "HBMain" )
This._Bind( This.Controls.UpButton , "_MoveElement" )
;Down Button
This.Controls.DownButton := Gui.Add( "Button" , "xs y+5 w70" , "Down" , "HBMain" )
This._Bind( This.Controls.DownButton , "_MoveElement" )
;Clipboard Button
This.Controls.ClipButton := Gui.Add( "Button" , "xs y+5 w70" , "Clipboard" , "HBMain" )
This._Bind( This.Controls.ClipButton , "_ClipProject" )
;Update Button
This.Controls.UpdateButton := Gui.Add( "Button" , "xs y+5 w70" , "Update" , "HBMain" )
This._Bind( This.Controls.UpdateButton , "_UpdateProject" )
Gui.Font( "Segoe UI" , "s8 Bold Q5" , "HBMain" )
;Prototype text line
This.Controls.PrototypeEdit := Gui.Add( "Edit" , "cPurple xm w330 r1 Center Border ReadOnly " , "" , "HBMain" )
;param1
This.Controls.Param1Text := Gui.Add( "Text" , "cRed x30 y+20 w70 r1" , "Param1:" , "HBMain" )
This.Controls.Param1Edit := Gui.Add( "Edit" , "c336699 x+10 yp-2 w200 r1 center" ,, "HBMain" )
;param2
This.Controls.Param2Text := Gui.Add( "Text" , "cRed x30 y+10 w70 r1" , "Param2:" , "HBMain" )
This.Controls.Param2Edit := Gui.Add( "Edit" , "c336699 x+10 yp-2 w200 r1 center" ,, "HBMain" )
;param3
This.Controls.Param3Text := Gui.Add( "Text" , "cRed x30 y+10 w70 r1" , "Param3:" , "HBMain" )
This.Controls.Param3Edit := Gui.Add( "Edit" , "c336699 x+10 yp-2 w200 r1 center" ,, "HBMain" )
;param4
This.Controls.Param4Text := Gui.Add( "Text" , "cRed x30 y+10 w70 r1" , "Param4:" , "HBMain" )
This.Controls.Param4Edit := Gui.Add( "Edit" , "c336699 x+10 yp-2 w200 r1 center" ,, "HBMain" )
;param5
This.Controls.Param5Text := Gui.Add( "Text" , "cRed x30 y+10 w70 r1" , "Param5:" , "HBMain" )
This.Controls.Param5Edit := Gui.Add( "Edit" , "c336699 x+10 yp-2 w200 r1 center" ,, "HBMain" )
Gui.Show( , "Gui Prototype Maker" , "HBMain" )
This.Elements := []
This.ElementActive := ""
This.ElementCount := 0
This.ElementList := ""
This.Clone := 0
}
_ClipProject(){
This.Output := 1
This.Clip := "`nAutoGui := {} `n"
This._UpdateProject()
}
_AddNewWindow(){
This.Val := "New"
This._AddElement()
}
_AddAddControl(){
This.Val := "Add"
This._AddElement()
}
_AddShowWindow(){
This.Val := "Show"
This._AddElement( )
}
_SetDefaults(){
for k, v in This.ParamCountList[ This.Elements[ This.ElementActive ].Method ].Defaults
This.Elements[ This.ElementCount ][k] := v
This.Elements[ This.ElementCount ][ "Param" This.ParamCountList[ This.Elements[ This.ElementActive ].Method ].Count ] := This.GUIName
}
_UpdateProject(){
Gui.Destroy( This.GUIName )
Loop, % This.ParamCountList[ This.Elements[ This.ElementActive ].Method ].Count
This.Elements[ This.ElementActive ][ "Param" A_Index ] := Gui.Get( This.Controls[ "Param" A_Index "Edit" ] ,, "HBMain" )
This._UpdateElementListBox()
This._RunGui()
}
_RunGui(){
Loop, % This.ElementCount {
This._Switch( This.Elements[ A_Index ].Method , This.Elements[ A_Index ] )
}
if( This.output ){
Clipboard := This.Clip
sleep, 200
This.Clip := ""
This.output := 0
loop 2
SoundBeep, 500
}
}
_Switch( Input , obj ){
local temp , parambackup , ta
Switch Input
{
case "New":
if( This.output ){
This.Clip .= "`nAutoGui." obj.param3 ":= {}`n"
This.Clip .= "AutoGui." obj.param3 ".Controls := {} `n"
This.Clip .= "AutoGui." obj.param3 ".Handles := [] `n`n"
This.Clip .= "Gui, " obj.param3 ":New, " obj.param2 " +hwndHwnd `n"
This.Clip .= "AutoGui." obj.param3 ".Hwnd := hwnd `n`n"
}else{
temp := obj.Param1
%Temp% := Gui.New( obj.param2 , obj.param3 )
}
case "Show":
if( This.output ){
This.Clip .= "Gui, " obj.param3 ":Show, " obj.param1 ", " obj.param2 " `n"
}else{
Gui.Show( obj.param1 , obj.param2 , obj.param3 )
}
case "Hide":
if( This.output ){
This.Clip .= "Gui, " obj.param1 ":Hide,`n"
}else{
Gui.Hide( obj.param1 )
}
case "Enable":
if( This.output ){
This.Clip .= "Gui, " obj.param1 ":-Disabled,`n"
}else{
Gui.Enable( obj.param1 )
}
case "Disable":
if( This.output ){
This.Clip .= "Gui, " obj.param1 ":+Disabled,`n"
}else{
Gui.Disable( obj.param1 )
}
case "Destroy":
if( This.output ){
This.Clip .= "Gui, " obj.param1 ":Destroy,`n"
}else{
Gui.Destroy( obj.param1 )
}
case "Get":
if( This.output ){
This.Clip .= "GuiControlGet, " obj.param1 " , " obj.param4 ": " obj.param3 " , " obj.param2 "`n"
}else{
temp := obj.Param1
%Temp% := Gui.Get( obj.param2 , obj.param3 , obj.param4 )
}
case "Set":
if( This.output ){
This.Clip .= "GuiControl, " obj.param4 ":" obj.param3 " , " obj.param1 " , " obj.param2 "`n"
}else{
Gui.Set( obj.param1 , obj.param2 , obj.param3 , obj.param4 )
}
case "Margin":
if( This.output ){
This.Clip .= "Gui, " obj.param3 ":Margin, " obj.param1 " , " obj.param2 "`n"
}else{
Gui.Margin( obj.param1 , obj.param2 , obj.param3 )
}
case "Color":
if( This.output ){
This.Clip .= "Gui, " obj.param3 ":Color, " obj.param1 " , " obj.param2 "`n"
}else{
Gui.Color( obj.param1 , obj.param2 , obj.param3 )
}
case "WindowPosition":
if( This.output ){
This.Clip .= obj.param1 ":= Gui.WindowPosition( " obj.param2 " )`n"
}else{
temp := obj.param1
%temp% := Gui.WindowPosition( obj.param2 )
}
case "ControlPosition":
if( This.output ){
This.Clip .= obj.param1 ":= Gui.ControlPosition( " obj.param2 " , " obj.param3 " )`n"
}else{
temp := obj.param1
%temp% := Gui.ControlPosition( obj.param2 , obj.param3 )
}
case "Add":
if( This.output ){
This.Clip .= ";" obj.param2 "`nGui, " obj.param5 ":Add, " obj.param2 " ," obj.param3 " hwndhwnd , " obj.param4 "`n"
This.Clip .= "AutoGui." obj.param5 "." obj.param1 " := { Hwnd: hwnd , Value: """ obj.param4 """ }`n"
This.Clip .= "AutoGui." obj.param5 ".Handles[hwnd] := """ obj.param1 """`n`n"
}else{
temp := obj.param1
if( instr( obj.param3 , "g" ) ){
ta := StrSplit( obj.param3 , " " )
loop, % ta.Length() {
if( instr( ta[A_index] , "g" ) != 1 )
parambackup .= ta[A_Index] " "
}
}else{
parambackup := obj.param3
}
%temp% := Gui.Add( obj.param2 , parambackup , obj.param4 , obj.param5 )
}
case "Font":
if( This.output ){
This.Clip .= "Gui, " obj.param3 ":Font, " obj.param2 " , " obj.param1 "`n"
}else{
Gui.Font( obj.param1 , obj.param2 , obj.param3 )
}
case "Options":
if( This.output ){
This.Clip .= "Gui, " obj.param2 ":" obj.param1 "`n"
}else{
Gui.Options( obj.param1 , obj.param2 )
}
case "Bind":
ToolTip, Bind Not avaialable in the editor
sleep, 1000
ToolTip,
}
}
_MoveElement(){
local temp
MouseGetPos,,,, ctrl , 2
if( ctrl = This.Controls.UpButton ){
if( ( This.ElementActive - 1 ) < 1 )
return
temp := This.Elements[ This.ElementActive ]
This.Elements[ This.ElementActive ] := This.Elements[ This.ElementActive - 1 ]
This.Elements[ This.ElementActive - 1 ] := temp
--This.ElementActive
}else{
if( ( This.ElementActive + 1 ) > This.ElementCount )
return
temp := This.Elements[ This.ElementActive ]
This.Elements[ This.ElementActive ] := This.Elements[ This.ElementActive + 1 ]
This.Elements[ This.ElementActive + 1 ] := temp
++This.ElementActive
}
This._UpdateElementListBox()
}
_CopyElement(){
This.Clone := 1
This._AddElement()
}
_ToggleLock(){
Gui.Set( This.Controls.RemoveButton , "" , ( Gui.Get( This.Controls.LockCheckBox , , "HBMain" ) ) ? ( "Enable" ) : ( "Disable" ) , "HBMain" )
}
_SelectElement(){
This._GetEdits()
This.ElementActive := Gui.Get( This.Controls.ElementListBox , , "HBMain" )
This._SetEdits()
This._UpdateElementListBox()
}
_Bind( Control , Method , Name := "HBMain" ){
local fn := This[ Method ].Bind( This )
Gui.Set( Control , fn , "+g" , Name )
}
_RemoveElement(){
if( !This.ElementCount )
return
This.Elements.RemoveAt( This.ElementActive )
This.ElementCount--
( This.ElementActive > This.ElementCount ) ? ( This.ElementActive := This.ElementCount )
This._UpdateElementListBox()
This._SetEdits()
}
_AddElement(){
This._GetEdits()
if( This.Clone && !This.Clone := 0 ){
This.Elements[ This.ElementCount + 1 ] := {}
for k, v in This.Elements[ This.ElementActive ]
This.Elements[ This.ElementCount +1 ][k] := v
This.ElementActive := ++This.ElementCount
}else{
This.ElementActive := ++This.ElementCount
This.Elements[ This.ElementCount ] := {}
if(!This.Val){
This.Elements[ This.ElementCount ].Method := Gui.Get( This.Controls.MethodDDL ,, "HBMain" )
}else {
This.Elements[ This.ElementCount ].Method := This.Val
This.Val := 0
}
This._SetDefaults()
}
This._UpdateElementListBox()
This._SetEdits()
}
_SetEdits(){
Loop, % 5
Gui.Set( This.Controls[ "Param" A_Index "Edit" ] , "" , "Hide" , "HBMain" )
, Gui.Set( This.Controls[ "Param" A_Index "Text" ] , "" , "Hide" , "HBMain" )
Loop, % This.ParamCountList[ This.Elements[ This.ElementActive ].Method ].Count
Gui.Set( This.Controls[ "Param" A_Index "Edit" ] , "" , "Show" , "HBMain" )
, Gui.Set( This.Controls[ "Param" A_Index "Text" ] , "" , "Show" , "HBMain" )
Loop, % This.ParamCountList[ This.Elements[ This.ElementActive ].Method ].Count
Gui.Set( This.Controls[ "Param" A_Index "Edit" ] , This.Elements[ This.ElementActive ][ "Param" A_Index ] ,, "HBMain")
Gui.Set( This.Controls.PrototypeEdit , This.ParamCountList[ This.Elements[ This.ElementActive ].Method ].Prototype , , "HBMain" )
Gui.Show( "AutoSize" , , "HBMain" )
}
_GetEdits(){
local tn := This.GuiName
Loop, % This.ParamCountList[ This.Elements[ This.ElementActive ].Method ].Count
This.Elements[ This.ElementActive ][ "Param" A_Index ] := Gui.Get( This.Controls[ "Param" A_Index "Edit" ] ,, "HBMain" )
This.GuiName := This.Elements[ This.ElementActive ][ "Param" This.ParamCountList[ This.Elements[ This.ElementActive ].Method ].Count ]
( !This.GuiName ) ? ( This.GuiName := tn )
}
_UpdateElementListBox(){
This._GetElementList()
Gui.Set( This.Controls.ElementListBox , This.ElementList , , "HBMain" )
Gui.Set( This.Controls.ElementListBox , This.ElementActive , "Choose" , "HBMain" )
}
_GetElementList(){
This.ElementList := "~"
Loop, % This.ElementCount {
if( This.Elements[ A_Index ].Method = "Add")
This.ElementList .= This.Elements[ A_Index ].Method "`t" This.Elements[ A_Index ].Param2 "`t`t" This.Elements[ A_Index ].Param4 "~"
else if( This.Elements[ A_Index ].Method = "Margin" )
This.ElementList .= This.Elements[ A_Index ].Method "`t`t`t" This.Elements[ A_Index ].Param1 "`t" This.Elements[ A_Index ].Param2 "~"
else if( This.Elements[ A_Index ].Method = "Color" )
This.ElementList .= This.Elements[ A_Index ].Method "`t`t`t" This.Elements[ A_Index ].Param1 "`t" This.Elements[ A_Index ].Param2 "~"
else if( This.Elements[ A_Index ].Method = "New" )
This.ElementList .= This.Elements[ A_Index ].Method "`t" This.Elements[ A_Index ].Param3 "`t`t" This.Elements[ A_Index ].Param2 "~"
else if( This.Elements[ A_Index ].Method = "Font" )
This.ElementList .= This.Elements[ A_Index ].Method "`t`t" This.Elements[ A_Index ].Param1 "`t`t" This.Elements[ A_Index ].Param2 "~"
else if( This.Elements[ A_Index ].Method = "Options" )
This.ElementList .= This.Elements[ A_Index ].Method "`t`t`t" This.Elements[ A_Index ].Param1 "~"
else
This.ElementList .= This.Elements[ A_Index ].Method "~"
}
}
}
class Gui {
;Written By: Hellbent
;Date: Sept 9th, 2021
New( Options := "+AlwaysOnTop" , Name := 1 ){
local hwnd
Gui, % Name ":New", % Options " hwndhwnd "
Gui[Name] := {}
Gui[Name].ControlCount := 0
Gui[Name].Handles := []
Gui[Name].Controls := []
Gui[Name].Hwnd := hwnd
Gui[Hwnd] := Gui[Name]
return hwnd
}
Show( Options := "" , Title := "" , Name := 1 ){
Gui, % Name ":Show", % Options, % Title
}
Hide( Name := 1 ){
Gui, % Name ":Hide"
}
Enable( Name := 1 ){
Gui, % Name ":-Disabled"
}
Disable( Name := 1 ){
Gui, % Name ":+Disabled"
}
Destroy( Name := 1 ){
Gui, % Name ":Destroy"
Gui[Name] := ""
}
Get( Control , SubCommand := "" , Name := 1 ){
local output
GuiControlGet, output, % Name ":" SubCommand, % Control
return output
}
Set( Control , Value := "" , SubCommand := "" , Name := 1 ){
GuiControl, % Name ":" SubCommand , % Control , % Value
}
Margin( x := 10 , y := 10 , Name := 1 ){
Gui, % Name ":Margin", % x , % y
}
Color( Color1 := "22262a" , Color2 := "000000" , Name := 1 ){
Gui, % Name ":Color", % Color1 , % Color2
}
WindowPosition( Hwnd ){
local x , y , w , h
WinGetPos, x , y , w , h , % "ahk_id " Hwnd
return { X: x , Y: y , W: w , H: h }
}
ControlPosition( Hwnd , Name := 1 ){
local x , y , w , h , pos
GuiControlGet, pos , % Name ":pos", % Hwnd
return { X: x , Y: y , W: w , H: h }
}
Add( Type := "Button" , Options := "" , Display := "" , Name := 1 ){
local hwnd
Gui, % Name ":Add", % Type, % Options " hwndhwnd " , % Display
return Gui[Name].Controls[ ( Gui[Name].Handles[ hwnd ] := ++Gui[Name].ControlCount ) ] := hwnd
}
Font( Font , Options := "" , Name := 1 ){
Gui, % Name ":Font", % Options, % Font
}
Options( Options , Name := 1 ){
Gui, % Name ":" Options
}
Bind( Control , Method , BoundObject , Name := 1 ){
local fn := Func( Method ).Bind( BoundObject )
GuiControl, % Name ":+g", % Control, % fn
}
Helper(){
Gui.Helper := {}
Gui.Helper.MethodString := "New||Show|Hide|Enable|Disable|Destroy|Get|Set|Margin|Color|WindowPosition|ControlPosition|Add|Font|Options|Bind|"
Gui.Helper.MethodList := {}
Gui.Helper.MethodList.New := "GuiHwnd := Gui.New( options := ""+AlwaysOnTop"" , Name := 1 )"
Gui.Helper.MethodList.Show := "Gui.Show( Options := """" , Title := "" , Name := 1 )"
Gui.Helper.MethodList.Hide := "Gui.Hide( Name := 1 )"
Gui.Helper.MethodList.Enable := "Gui.Enable( Name := 1 )"
Gui.Helper.MethodList.Disable := "Gui.Disable( Name := 1 )"
Gui.Helper.MethodList.Destroy := "Gui.Destroy( Name := 1 )"
Gui.Helper.MethodList.Get := "Output := Gui.Get( Control , SubCommand := """" , Name := 1 )"
Gui.Helper.MethodList.Set := "Gui.Set( Control , Value , SubCommand := """" , Name := 1 )"
Gui.Helper.MethodList.Margin := "Gui.Margin( x := 10 , y := 10 , Name := 1 )"
Gui.Helper.MethodList.Color := "Gui.Color( Color1 := ""F0F0F0"" , Color2 := ""FFFFFF"" , Name := 1 )"
Gui.Helper.MethodList.WindowPosition := "Pos := Gui.WindowPosition( GuiHwnd )"
Gui.Helper.MethodList.ControlPosition := "Pos := Gui.ControlPosition( Control , Name := 1 )"
Gui.Helper.MethodList.Add := "ControlHwnd := Gui.Add( Type := ""Button"" , Options := """" , Display := """" , Name := 1 )"
Gui.Helper.MethodList.Font := "Gui.Font( Font := """" , Options := """" , Name := 1 )"
Gui.Helper.MethodList.Options := "Gui.Options( Options := """" , Name := 1 )"
Gui.Helper.MethodList.Bind := "Gui.Bind( Control , Method , BoundObject , Name := 1 )"
Gui.Destroy( "GuiHelper" )
Gui.New( "+AlwaysOnTop" , "GuiHelper" , "GuiHelper" )
Gui.Color( "22262a" , "62768a" , "GuiHelper" )
Gui.Margin( 10 , 20 , "GuiHelper" )
Gui.Font( "Segoe UI" , "s10 cWhite Bold Q5" , Name := "GuiHelper" )
Gui.Helper.ListBox := Gui.Add( "ListBox" , "xm ym w350 r" Gui.Helper.MethodList.Count() , Gui.Helper.MethodString , "GuiHelper" )
Gui.Helper.Button := Gui.Add( "Button" , "xm w350 " , "Clipboard Method" , "GuiHelper" )
Gui.Bind( Gui.Helper.Button , "Gui._HelperClipIt" , "" , "GuiHelper" )
Gui.Bind( Gui.Helper.ListBox , "Gui._HelperDisplayIt" , "" , "GuiHelper" )
Gui.Helper.Edit := Gui.Add( "Edit" , "xm w350 r1" , "" , "GuiHelper" )
Gui.Show( , , "GuiHelper" )
}
_HelperClipIt(){
local selected := Gui.Get( Gui.Helper.ListBox ,, "GuiHelper" ) , cc := Gui.Helper.MethodList
Clipboard := Gui.Helper.MethodList[selected]
}
_HelperDisplayIt(){
local selected := Gui.Get( Gui.Helper.ListBox ,, "GuiHelper" ) , cc := Gui.Helper.MethodList
Gui.Set( Gui.Helper.Edit , Gui.Helper.MethodList[selected] , , "GuiHelper" )
}
}
This is the part from it that runs the code.
Code: Select all
_UpdateProject(){
Gui.Destroy( This.GUIName )
Loop, % This.ParamCountList[ This.Elements[ This.ElementActive ].Method ].Count
This.Elements[ This.ElementActive ][ "Param" A_Index ] := Gui.Get( This.Controls[ "Param" A_Index "Edit" ] ,, "HBMain" )
This._UpdateElementListBox()
This._RunGui()
}
_RunGui(){
Loop, % This.ElementCount {
This._Switch( This.Elements[ A_Index ].Method , This.Elements[ A_Index ] )
}
if( This.output ){
Clipboard := This.Clip
sleep, 200
This.Clip := ""
This.output := 0
loop 2
SoundBeep, 500
}
}
_Switch( Input , obj ){
local temp , parambackup , ta
Switch Input
{
case "New":
if( This.output ){
This.Clip .= "`nAutoGui." obj.param3 ":= {}`n"
This.Clip .= "AutoGui." obj.param3 ".Controls := {} `n"
This.Clip .= "AutoGui." obj.param3 ".Handles := [] `n`n"
This.Clip .= "Gui, " obj.param3 ":New, " obj.param2 " +hwndHwnd `n"
This.Clip .= "AutoGui." obj.param3 ".Hwnd := hwnd `n`n"
}else{
temp := obj.Param1
%Temp% := Gui.New( obj.param2 , obj.param3 )
}
case "Show":
if( This.output ){
This.Clip .= "Gui, " obj.param3 ":Show, " obj.param1 ", " obj.param2 " `n"
}else{
Gui.Show( obj.param1 , obj.param2 , obj.param3 )
}
case "Hide":
if( This.output ){
This.Clip .= "Gui, " obj.param1 ":Hide,`n"
}else{
Gui.Hide( obj.param1 )
}
case "Enable":
if( This.output ){
This.Clip .= "Gui, " obj.param1 ":-Disabled,`n"
}else{
Gui.Enable( obj.param1 )
}
case "Disable":
if( This.output ){
This.Clip .= "Gui, " obj.param1 ":+Disabled,`n"
}else{
Gui.Disable( obj.param1 )
}
case "Destroy":
if( This.output ){
This.Clip .= "Gui, " obj.param1 ":Destroy,`n"
}else{
Gui.Destroy( obj.param1 )
}
case "Get":
if( This.output ){
This.Clip .= "GuiControlGet, " obj.param1 " , " obj.param4 ": " obj.param3 " , " obj.param2 "`n"
}else{
temp := obj.Param1
%Temp% := Gui.Get( obj.param2 , obj.param3 , obj.param4 )
}
case "Set":
if( This.output ){
This.Clip .= "GuiControl, " obj.param4 ":" obj.param3 " , " obj.param1 " , " obj.param2 "`n"
}else{
Gui.Set( obj.param1 , obj.param2 , obj.param3 , obj.param4 )
}
case "Margin":
if( This.output ){
This.Clip .= "Gui, " obj.param3 ":Margin, " obj.param1 " , " obj.param2 "`n"
}else{
Gui.Margin( obj.param1 , obj.param2 , obj.param3 )
}
case "Color":
if( This.output ){
This.Clip .= "Gui, " obj.param3 ":Color, " obj.param1 " , " obj.param2 "`n"
}else{
Gui.Color( obj.param1 , obj.param2 , obj.param3 )
}
case "WindowPosition":
if( This.output ){
This.Clip .= obj.param1 ":= Gui.WindowPosition( " obj.param2 " )`n"
}else{
temp := obj.param1
%temp% := Gui.WindowPosition( obj.param2 )
}
case "ControlPosition":
if( This.output ){
This.Clip .= obj.param1 ":= Gui.ControlPosition( " obj.param2 " , " obj.param3 " )`n"
}else{
temp := obj.param1
%temp% := Gui.ControlPosition( obj.param2 , obj.param3 )
}
case "Add":
if( This.output ){
This.Clip .= ";" obj.param2 "`nGui, " obj.param5 ":Add, " obj.param2 " ," obj.param3 " hwndhwnd , " obj.param4 "`n"
This.Clip .= "AutoGui." obj.param5 "." obj.param1 " := { Hwnd: hwnd , Value: """ obj.param4 """ }`n"
This.Clip .= "AutoGui." obj.param5 ".Handles[hwnd] := """ obj.param1 """`n`n"
}else{
temp := obj.param1
if( instr( obj.param3 , "g" ) ){
ta := StrSplit( obj.param3 , " " )
loop, % ta.Length() {
if( instr( ta[A_index] , "g" ) != 1 )
parambackup .= ta[A_Index] " "
}
}else{
parambackup := obj.param3
}
%temp% := Gui.Add( obj.param2 , parambackup , obj.param4 , obj.param5 )
}
case "Font":
if( This.output ){
This.Clip .= "Gui, " obj.param3 ":Font, " obj.param2 " , " obj.param1 "`n"
}else{
Gui.Font( obj.param1 , obj.param2 , obj.param3 )
}
case "Options":
if( This.output ){
This.Clip .= "Gui, " obj.param2 ":" obj.param1 "`n"
}else{
Gui.Options( obj.param1 , obj.param2 )
}
case "Bind":
ToolTip, Bind Not avaialable in the editor
sleep, 1000
ToolTip,
}
}
Re: Deconstructing and performing a written command into its own script
This is probably the simplest example I have.
viewtopic.php?f=6&t=60949
You can also safely write data to a non compiled script by including something like this in your script and then using IniRead and IniWrite to save values between reloads.
You can even mask the use of such tricks as a simple security measure
viewtopic.php?f=6&t=60949
Code: Select all
SortCommandList(){
GuiControlGet,Commands,1:,Commands
stringleft,tep,Commands,1
if(tep="*"){
CMove:="",CTimes:="",XOff:="",YOff:="",TypeC:="Left",RTimes:=1,Send_Stuff:=""
Loop, Parse, Commands,*
{
(A_Index=2)?(RTimes:=A_LoopField)
:(A_Index=3)?(CMove:=A_LoopField)
:(A_Index=4)?(CTimes:=A_LoopField)
:(A_Index=5)?(XOff:=A_LoopField)
:(A_Index=6)?(YOff:=A_LoopField)
:(A_Index=7)?(TypeC:=A_LoopField)
:(A_Index=8)?(M_Delay:=A_LoopField)
:(A_Index=9)?(Key_Delay:=A_LoopField)
:(A_Index=10)?(Delay:=A_LoopField)
:(A_Index=11)?(Send_Stuff:=A_LoopField)
}
Return True
}else {
Gui,1:+OwnDialogs
MsgBox,,Error,There is a error with your command setup
Stop:=1
return False
}
}
Click_Function(x,y,LT,BTN){
CoordMode,Mouse,Screen
SetMouseDelay,%M_Delay%
index:=0
While(Index<LT&&!Stop){
Click %BTN%,%x%,%y%
index++
}
}
Move_Function(x,y){
CoordMode,Mouse,Screen
MouseMove,x,y,0
}
Send_Function(SS){
SetKeyDelay,%Key_Delay%
Send,% SS
}
Start_Search(){
Stop:=0
if(!SortCommandList())
return
GuiControlGet,Color_Edit,1:,Color_Edit
GuiControlGet,Variation,1:,Variation
While(!Stop){
PixelSearch,px,py,X_Pos,Y_Pos,cx2,cy2,Color_Edit,Variation,Fast|RGB
if(!ErrorLevel&&Truth[1].State=1){
if(CMove=1)
Click_Function(px+XOff,py+YOff,CTimes,TypeC)
else if(CMove=0&&CTimes>=1)
Move_Function(px+XOff,py+YOff)
if(Send_Stuff)
Send_Function(Send_Stuff)
if(RTimes=0){
Stop:=1
return
}
Sleep,% Delay
}else if(ErrorLevel=1&&Truth[2].State=1){
if(Send_Stuff)
Send_Function(Send_Stuff)
if(RTimes=0){
Stop:=1
return
}
Sleep,% Delay
}
}
}
Code: Select all
/*
[Section]
key1=
key2=
key3=
key4=
keyETC...=
*/
Who is online
Users browsing this forum: OrangeCat and 321 guests