Thanks guys! Hugo (and anyone else) could you tell me why this code doesn't work! I've tried your way and it doesn't change the output for me. The top variable %A_Index%_text is from an edit box (i.e. v1_text) and the bottom %A_Index%_program is from a Fileselectfile (i.e. 1_program). Is there some difference when working with those two variables?
The only problem with the script is that the code (simplified here) works for the top but not for the bottom one (problem code + associated code is red).
GuiControlGet, hotkey, ,%A_Index%_text
Fileappend,
%A_Index%::send %hotkey%
GuiControlGet, file, ,%A_Index%_program
Fileappend,
%A_Index%::run %file%
The Gui basically remaps 5 (2 for now) buttons (1-5) to whatever you want them to be. It appends an .ahk file, soon to be standalone .exe so that it can be more portable. I suspect there's some logic/spelling error I'm too tired to see.
Code:
;################################################
;This program is unfinished but working
;
;
;################################################
Gui, Font, Bold
Gui, Add, Tab2, x0 y0 w726 h381 , Main|Help
Gui, Tab, Main
;###############
;This is the contents of Tab Main - Button 1
;###############
Gui, Font,
Gui, Add, CheckBox, x126 y40 w17 h20 v1hotkey, 1_Button_hotkey
Gui, Add, CheckBox, x126 y76 w17 h20 v1program, 1_Button_program
Gui, Font, underline
Gui, Add, CheckBox, x126 y106 w100 h20 v1mouse, Move Mouse
Gui, Font,
Gui, Add, CheckBox, x143 y148 w86 h20 v1leftclick, Left Click?
Gui, Add, CheckBox, x143 y169 w86 h19 v1doubleclick, Double Click?
Gui, Font, underline
Gui, Add, CheckBox, x126 y195 w100 h18 v1Direction, Arrow Buttons
Gui, Font,
Gui, Add, CheckBox, x160 y210 w40 h20 v1up, Up
Gui, Add, CheckBox, x160 y230 w45 h20 v1down, Down
Gui, Add, CheckBox, x135 y220 w25 h20 v1left, L
Gui, Add, CheckBox, x205 y220 w25 h20 v1right, R
Gui, Font, underline
Gui, Add, Text, x10 y20 w110 h40 , Simple Instructions
Gui, Font,
Gui, Add, Text, x10 y40 w110 h300 , Tick ONE Main box and any ONE sub box `n`n Use 'text' to type any
text you want e.g. 'hello' or 'P'`n`n Use 'AnyFile_' to open anything e.g. a music file or Paint
program `n`n Use 'Move Mouse' to move the mouse anywhere and click or double click when it gets there
(tick a box)`n`n Use 'Arrow Buttons' to simulate the arrow keys
Gui, Add, Edit, x146 y40 w70 h20 v1_text, any text
Gui, Add, Edit, x146 y126 w30 h20 v1xmouse, X
Gui, Add, Edit, x186 y126 w30 h20 v1ymouse, Y
Gui, Font, underline
Gui, Add, Button, x146 y76 w70 h20 , AnyFile_1
Gui, Font,
Gui, Add, GroupBox, x120 y27 w115 h235 +, Button 1
;###############
;This is the contents of Tab Main - Button 2
;###############
Gui, Font,
Gui, Add, CheckBox, x241 y40 w17 h20 v2hotkey, 2_Button_hotkey
Gui, Add, CheckBox, x241 y76 w17 h20 v2program, 2_Button_program
Gui, Font, underline
Gui, Add, CheckBox, x241 y106 w100 h20 v2mouse, Move Mouse
Gui, Font,
Gui, Add, CheckBox, x258 y148 w86 h20 v2leftclick, Left Click?
Gui, Add, CheckBox, x258 y169 w86 h19 v2doubleclick, Double Click?
Gui, Font, underline
Gui, Add, CheckBox, x241 y195 w100 h18 v2Direction, Arrow Buttons
Gui, Font,
Gui, Add, CheckBox, x275 y210 w40 h20 v2up, Up
Gui, Add, CheckBox, x275 y230 w45 h20 v2down, Down
Gui, Add, CheckBox, x250 y220 w25 h20 v2left, L
Gui, Add, CheckBox, x320 y220 w25 h20 v2right, R
Gui, Add, Edit, x261 y40 w70 h20 v2_text, any text
Gui, Add, Edit, x261 y126 w30 h20 v2xmouse, X
Gui, Add, Edit, x301 y126 w30 h20 v2ymouse, Y
Gui, Font, underline
Gui, Add, Button, x261 y76 w70 h20 , AnyFile_2
Gui, Font,
Gui, Add, GroupBox, x237 y27 w115 h235 +, Button 2
;################
;This is going to be the contents of button 3
;################
Gui, Add, Button, x26 y306 w100 h30 , Create_Program
Gui, Add, Button, x226 y306 w100 h30 , Exit
Gui, Tab, Help
Gui, Add, Text, x20 y20 w110 h40 , More Instructions
Gui, Show, x131 y91 h381 w726, Project Creator v1.07
Return
ButtonAnyFile_1:
FileSelectFile, 1_program, , , 1. Choose a file,
return
ButtonAnyFile_2:
FileSelectFile, 2_program, , , 2. Choose a file,
return
ButtonAnyFile_3:
FileSelectFile, 3_program, , , 3. Choose a file,
return
ButtonAnyFile_4:
FileSelectFile, 4_program, , , 4. Choose a file,
return
ButtonAnyFile_5:
FileSelectFile, 5_program, , , 5. Choose a file,
return
ButtonCreate_Program:
{
Gui, submit, NoHide
FileSelectFile, Location, S16, , Select a Location and Filename for Your Project
}
;##############
;"Location" means both the location and filename in a single variable
;##############
;########################
;The next part appends (or creates) a file with the input fields chosen from the gui
;########################
Fileappend,
(
CoordMode, Mouse, Screen
esc::exitapp
), %location%.ahk
Loop, 5
{
;#########
;This assigns any text or hot keys to the button
;#########
If %A_Index%hotkey = 1
{
GuiControlGet, hotkey, ,%A_Index%_text
Fileappend,
(
%A_Index%::send %hotkey%
), %location%.ahk
}
;#########
;This assigns ANY files to the button
;#########
If %A_Index%program = 1
{
GuiControlGet, file, ,%A_Index%_program
Fileappend,
(
%A_Index%::run %file%
), %location%.ahk
}
;###################
;These check for the direction arrow options
;###################
If %A_Index%Direction = 1
{
If %A_Index%left = 1
{
Fileappend,
(
%A_Index%::
Send {left down}
SetTimer, WaitFor%A_Index%, 30
return
WaitFor%A_Index%:
if not GetKeyState("%A_Index%")
{
Send {left up}
SetTimer, WaitFor%A_Index%, off
return
}
Send {left down}
return
), %location%.ahk
}
If %A_Index%right = 1
{
Fileappend,
(
%A_Index%::
Send {right down}
SetTimer, WaitFor%A_Index%, 30
return
WaitFor%A_Index%:
if not GetKeyState("%A_Index%")
{
Send {right up}
SetTimer, WaitFor%A_Index%, off
return
}
Send {right down}
return
), %location%.ahk
}
If %A_Index%up = 1
{
Fileappend,
(
%A_Index%::
Send {up down}
SetTimer, WaitFor%A_Index%, 30
return
WaitFor%A_Index%:
if not GetKeyState("%A_Index%")
{
Send {up up}
SetTimer, WaitFor%A_Index%, off
return
}
Send {up down}
return
), %location%.ahk
}
If %A_Index%down = 1
{
Fileappend,
(
%A_Index%::
Send {down down}
SetTimer, WaitFor%A_Index%, 30
return
WaitFor%A_Index%:
if not GetKeyState("%A_Index%")
{
Send {down up}
SetTimer, WaitFor%A_Index%, off
return
}
Send {down down}
return
), %location%.ahk
}
}
;##########################
;These check if the mouse option was chosen
;##########################
If (%A_Index%mouse == 1 AND %A_Index%leftclick == 0 AND %A_Index%doubleclick == 0)
{
GuiControlGet, mousexval, ,%A_Index%xmouse
GuiControlGet, mouseyval, ,%A_Index%ymouse
Fileappend,
(
%A_Index%::MouseMove, %mousexval%,%mouseyval%, ,
return
), %location%.ahk
}
If (%A_Index%leftclick == 1 AND %A_Index%mouse == 1)
{
GuiControlGet, mousexval, ,%A_Index%xmouse
GuiControlGet, mouseyval, ,%A_Index%ymouse
Fileappend,
(
%A_Index%::
MouseMove, %mousexval%,%mouseyval%, ,
Click
return
), %location%.ahk
}
If (%A_Index%doubleclick == 1 AND %A_Index%mouse == 1)
{
GuiControlGet, mousexval, ,%A_Index%xmouse
GuiControlGet, mouseyval, ,%A_Index%ymouse
Fileappend,
(
%A_Index%::
MouseMove, %mousexval%,%mouseyval%, ,
Click 2
return
), %location%.ahk
}
}
;#######################
;This loop checks the main checkboxes of each button for more than 1 tick and sends a file error
warning
;#######################
Loop, 5
{
If (%A_Index%Direction == 1 AND %A_Index%hotkey ==1 OR %A_Index%Direction == 1 AND %A_Index%program
==1 %A_Index%Direction == 1 AND %A_Index%mouse == 1 %A_Index%hotkey == 1 AND %A_Index%program == 1 OR
%A_Index%hotkey == 1 AND %A_Index%mouse == 1 OR %A_Index%program == 1 AND %A_Index%mouse == 1 OR
%A_Index%leftclick == 1 AND %A_Index%doubleclick == 1)
{
msgbox, Error! Option Conflict! `nPlease check the tick boxes for conflicts `nProject file
"%filename%" created but with errors
}
}
return
ButtonExit:
ExitApp
GuiClose:
ExitApp