-- AHK BASICS --

Helpful script writing tricks and HowTo's
User avatar
HinkerLoden
Posts: 93
Joined: 23 Mar 2016, 07:50
GitHub: HinkerLoden

-- AHK BASICS --

28 Mar 2016, 19:14

I want to create a new Tutorial for beginners. I am a complete autodidact coder and i want to get here some simple things in the right order. With helping others i can practice my coding.
UNDER CONSTRUCTION




    Finished Components


  • Commando-List sorted by Categories
  • SwissArmy Knife of (AHK) Coding
  • Structure Template v1.0





    Under Construction



  • GUI
  • Basic Syntax Introduction - If Calls / Loops / Label
  • Good Code Structure - The art of Code AHK - My opionion to order the Code into logical sections / blocks. Starting usage to explain with the Template.
  • Structure Template V.1.1 - Insert Basic GUI - Will be basis for upcoming HowTo´s
  • Workaround Windoze 10 - Scripts not working - Transparency - ... gimme links plz









1.) Basic Structure inside the AHK Script
  • General advices how to code and learn AHK
  • STRUCTURE TEMPLATE to get things in the right order
  • Some words about some important Script Environment Settings
  • The Official Tutorial / FAQ
  • Trial and Error





SwissArmy Knife of (AHK) Coding

  • How to use "=" and ":=" right
  • Variables and the % Usage
  • Functions - the Magic Expendable

Upcoming Tutorials



LoopTimer with If calls - Tutorial - Loops / Timer, continue,break, usage from Operators, Buildin-Variables


Gui - Tutorial - MsgBox-Inputbox, , Create Gui, Input/Output Handling (controlget,control,etc...), gLabel, Gui 2 data.ini transfer


Windows Environment - Open Windows/Programms - Read/ Get Information out of a window/control - Write / Edit a window


Input-Output - Hotkey Mouse and more Inputs,
Last edited by HinkerLoden on 03 Apr 2016, 15:44, edited 4 times in total.
User avatar
HinkerLoden
Posts: 93
Joined: 23 Mar 2016, 07:50
GitHub: HinkerLoden

Re: -- AHK BASICS --

28 Mar 2016, 19:15

General advices how to code and learn AHK


1.) Get a Editor with Texthiglightning
Notepad++ and Scite is free software.
Put the editor on the half of the screen and on the other side open your Browser or the AHK-Help File. Enough space to code and you got quick access if you need help.



STRUCTURE TEMPLATE to get things in the right order

I hope it helps to get the most used settings and give you a bit of orientation as a white sheet. The Setup is done in safe parameters that should prevent you to get mistakes that belong to the scriptsetup and not your code. As earlier you can handle the Outlay, as faster you can navigate inside the script. More time to learn the language. To hold a clear structure is really important. Nothing is more annoying, as to lose the plot.
So you should the following little things. Sure its a bit work more to do. But in the end you save more time and make the code more readable for you and for the community if you need help.
  • use the Comment Function often - helps to learn and give you a visual hook
  • try to avoid Numbers and use Variables for them , if you have to change a value, you can do that for the complete script inside with one variable
  • Learn how to use Functions - Your Lazy and Smart. Use Functions. There will be functions you can use for many scripts. If you recognize that there are lines in your script obviously repeat. Try to write a function for the code. Modify and reuse the script will be happen soon. Believe me. If the most Code inside the script is done by functions. Youre on the right way.
  • Order your script segments with visual hooks. Paste in Lines that give you orientation in which section inside the code your are.

    STRUCTURE TEMPLATE v1.0
    StructureTemplate.ahk
    STRUCTURE TEMPLATE v1.0
    (5.09 KiB) Downloaded 213 times


    Code: [Select all] [Expand] [Download] (STRUCTURE_TEMPLATE_v1.0.ahk)GeSHi © Codebox Plus





    Some words about some important Script Environment Settings

    STill under progress but it includes many settings that should prevent you from some silly easy errors at the start. Just read the comments inside the Template. It depends a bit what kind or stuff you want to do. But there is some really interesting things for Beginner
  • #SingleInstance force allows you to restart the script without closing it. Really usefull and save a lot off clicks
  • ShortCut ALT + X Exit the Script - Should your Mousecursor run crazy or you cant close the script , this is your red button.


    The Official Tutorial / FAQ


    Its ok. But for beginners it a bit hard to understand and the many Question here in the Forum shows that its not really a good help is, how to code. The explanations for the commands are good but the examples are mostly not really good. But use the Index to get quick infos about the Command-Parameter. you gonna use these really often.
    Read the Tutorial. But IMO its not really helpfull. But it dont hurts your much if you do it. Take it as a advanced appendix from this Tutorial 8-)

    Trial and Error

    Without it, you wont get it. But this is how you learn. Every mistake your make, you can clear it out and learn from it. IMO i think that one of the fascinating and motivating thing in coding. Its really a pleasure if you found the little Comma that hang up your code. Or a missing Percentage sign. Try to find the mistake inside the code yourself. I see to many guys asking here for a really silly problem and they wanna have a ready solution for there Project. On this way you dont gonna learn the really interesting things with AHK. So keep it up and dont be shy to ask here if you really stuck somewhere.
Last edited by HinkerLoden on 01 Apr 2016, 03:54, edited 2 times in total.
User avatar
HinkerLoden
Posts: 93
Joined: 23 Mar 2016, 07:50
GitHub: HinkerLoden

Re: -- AHK BASICS --

28 Mar 2016, 19:40

PLACEHOLDER
Last edited by HinkerLoden on 04 Apr 2016, 03:39, edited 1 time in total.
User avatar
HinkerLoden
Posts: 93
Joined: 23 Mar 2016, 07:50
GitHub: HinkerLoden

Re: -- AHK BASICS --

29 Mar 2016, 05:11

SwissArmy Knife of (AHK) Coding


4 Steps of Coding


INPUT ---> COMPARE ---> TRANSFER (STORE) --> OUTPUT

It should be a introduction for beginners. So i really have to say some things about structure of every the Script language. Again, i try to keep it simple and the Hardcore Coders will say its not right. These 4 steps are allways present, even if you dont notice them. In Simple Things you dont really need them, but the normal case your structure will look this way. The Important thing is it, that you dont mix them together. I show you what thats how crucial that is and what to do to hold the script structure in shape.

INPUTs CAN BE DONE
Mouse, Key, running Programs / Tasks, Window settings (Size, Position, Title, etc.,), GUI, OS Environment (Time, Version)
Every INPUTS ends into a Value what assigned to a Variable. Quite Simple. But Keep them separate in your Script.

COMPARE
Comparisons in 99% handles with If-Calls. Compare 2 or more Inputs if active, are they fulfill the Values you want to do something.
I think in most cases this should be the largest Part of your Script. I like it to integrate the If-Call inside a Timer.
The Timer is like a constant Loop within a defined Rotation Time. So it is possible to do Switch Timers on an off. You can control the several Processes with a defined time you need.
I recommend to do that right at the start up. I the practical case it working on this way really good.

TRANSFER - I really search for the right term here
The comparison Value now maybe got the Value TRUE or FALSE. But you need to bring the Value in a Format you want to use in the upcoming Output. So you advice a specific Color or Coordinate on this you can you use. Transform the Value in the right Format you need. I separate this because many Compares are only need one Transfer. Mostly done by Functions. ( Example: Put the ColorValue and the CoordinateXY with the same Progress into a Ini File / Array . )

It really important to have that in mind. You have to prepare ( convert / format ) your upcoming Output.

OUTPUT
All Input Sources can turn into a Output. But you have the use the right commando for it.
Usually done by :
Mouse,Key(combinations), safe into file / txt / Ini / pic / etc, Sound, GUI

Maybe the interesting part for starters. To do all the clicks that make the life easier. But remind that it only a litle part at the end of the script.




How to use "=" and ":=" right


Official Tutorial - Variables

I think here problem allready start. They explain Variables and mix right at begin "=" and ":=" Give it a go.
But i try to Explain it on an other way to get the difference and especially the practical usage and how the syntax working.

First you have to think different of the learned Math in School.
Not think from Left to Right inside the Operations. The ahk Code work from Right to Left


Var1 + Var2 --> Output

Output <-- Var1 + Var2

Thats one important think what drives me Crazy at the begin. No one tell you here. But you really have to know it and so you prevent many mistakes and understand the code better.




And yes. Its not really correct here. But on this way it helps me to get the difference between this 2 basic important things. I try to create some easy rules for me to prevent the wrong usage with Assignments "=" and Expressions ":=". And with the Percentage Signs it can get very tricky. Keey the following in mind and it help you at the start.

USE OF = ( Assignments )

1_Variable = 1_Value

Only ONE Variable is addressed to ONE Value. No Operator used in Assignments

Usage: Store a Value/String into the variable .

Code: [Select all] [Download] GeSHi © Codebox Plus

Example:
Variable_Integer = 123
Variable_String = Some Text to store in Variable



USE OF := ( Expressions )

Content Minimum one Operator and Minimum 2 Variable
OutPutVariable := 1_Variable + 2_Variable

Important Notes:
Text(strings) allways use in "quotation marks"
Never Use %Variable% here (Can do - but dont do this at the start !)
Never Use pure Numbers here


Special case - Transfer Variable

Usage:
Operations (Mathematic or Logical)
Tranfer Value into another Value
Combine Values with each other (Text and Numbers )



Code: [Select all] [Download] GeSHi © Codebox Plus

VarOutput := Input_Var1 + Input_Var2 				;Operation Mathematic

VarOutput := VarInput ;Tranfer Value into another Value

VarOutput12:= Input_Var1 . Input_Var2 ;the dot combine/merge them together



Now a mixed Example

;------------------------------

Code: [Select all] [Download] GeSHi © Codebox Plus


Input_Var1 = 2
Input_VarText = Input Variables

VarOutput := "In brackets you can get the Text between the " "`n`n" . Input_Var1 . Input_VarText . "`n`n" . "The dot merge it together"

MsgBox % VarOutput
return

Last edited by HinkerLoden on 29 Mar 2016, 12:37, edited 1 time in total.
User avatar
HinkerLoden
Posts: 93
Joined: 23 Mar 2016, 07:50
GitHub: HinkerLoden

Re: -- AHK BASICS --

29 Mar 2016, 12:24

Some more Placeholder - Maybe Software List here

Texteditors

GUI Creator

Librarys

Usefull AHK Coding Tools
User avatar
HinkerLoden
Posts: 93
Joined: 23 Mar 2016, 07:50
GitHub: HinkerLoden

Re: -- AHK BASICS --

29 Mar 2016, 16:40



https://autohotkey.com/docs/Variables.htm

Variables and the % Usage


I integrate here a the Sample from the Official Tutorial

a. When to use percents

One of the most common issues with AutoHotkey involving variables is when to use the percent signs (%). Hopefully this will clear some confusion.

When to use %'s:
  • When you are using Commands (see above) you use percent signs.
    -- Except when the parameter is OutputVar or InputVar.
  • When you are assigning a variable to a value using a traditional mode (an equal sign with no symbol in front of it). Example VarOutput = %VarInput%

When not to use %'s:
  • In parameters that are input or output variables, For example: StringLen, OutputVar, InputVar
  • On the left side of an assignment: Var = 123abc
  • On the left side of traditional (non-expression) if-statements: If Var1 < %Var2%
  • Everywhere in expressions. For example:
    If (Var1 != Var2)
    Var1 := Var2 + 100


Force an expression:

From the Official Help
An expression can be used in a parameter that does not directly support it (except OutputVar parameters) by preceding the expression with a percent sign and a space or tab. In [v1.1.21+], this prefix can be used in the InputVar parameters of all commands except the traditional IF commands (use If (expression) instead). This technique is often used to access arrays. For example:

Code: [Select all] [Download] (Forced-Expression.ahk)GeSHi © Codebox Plus

FileAppend, % MyArray[i], My File.txt
FileAppend, % MyPseudoArray%i%, My File.txt
MsgBox % "The variable MyVar contains " . MyVar . "."
Loop % Iterations + 1
WinSet, Transparent, % X + 100
Control, Choose, % CurrentSelection - 1


I implement some Examples in the Upcoming Functions




Functions - the Magic Expendable

Here are the Notes for the Official Help. Official Notes to Functions

USE FUNCTIONS WHENEVER YOU CAN
START USING THEM AS SOON AS POSSIBLE

Functions give you a great flexibility and you can use them for your next project. Maybe with little changes. I not really noticed them a long time , but its really great and it make sense to understand the functions at the start.
Functions are an universal instrument for many things. But the main thing is to automatic Codephrases.
So its possible to do all the Code with no Functions.

There are a bunch of advantages if you use Functions inside the code:

  • But your Code is much shorter As bigger your script grow, as more this aspect gets important. Without lose the Overview so quick in case of that.
  • Modify the Task getting quite easy
  • Use the Functions for your next Project - So if you put energy and work in one Function you can mostly use them inside another Script.
  • Safe Time to Navigate inside the Code, Write the Code, Analyzing / debugging

I am know that the starter dont really need functions at the start. But as early you beginn with functions. As quicker you can understand the ahk syntax and you are able to understand the the Examples in the forum better.




Give a function a practical relation. You notice that you are doing the following Codelines again and again

1.)Get the Coordinates from the active Cursor position
2.) Get the Color from the active Cursor position
3.) Compare with 3 Colors If Found the Color
4.) If Found - Wait between 1-2 seconds
5.) Move the Cursor relative from the Position if the Search was sucessfull 50pixel Down and 50pixel Right.
6.) Output the WaitTime

Copy / Download it and paste it into your Editor. Add the upcoming Changes yourself to for the practice.




Code: [Select all] [Expand] [Download] (Example.ahk)GeSHi © Codebox Plus






Structure from a Function

You have 2 parts :
1.) The Function Call inside the Code - Without Braces (only Bracktes)

2.) The Function at end of the Code - Braces include the Code


FunctionName ()

{
X = 5 ;Decline Vars - Cause all Variables are empty inside the Function
Y = 2

Output := X - Y ;a Task
return Output ; Return end the Function a give back ONE Value , but you can do a return without set any Variable / Output Value
}

Everything in the Braces is excecute if you put the Function FunctionName () in the Code. The Script dont stops and go ahead in the next Line.




Functions got there Limitations

Reminder:

  • Created Variables are only inside the Function Active
  • With return the Functions Stops
  • It is not possible to pass Clipboard, built-in variables, or environment variables to a function's ByRef parameter
  • Function give the only one Value back
  • avoid to use Label / Hotkey / Timer Inside a Function cause you cant get access outside of the function on it




Time to put something into a function. So we analyze first how many steps are done and where the code repeats.

1.)Get the Coordinates from the active Cursor position -1x
2.) Get the Color from the active Cursor position - 1x
3.) Compare with 3 Colors If Found the Color -3x
4.) If Found - Wait between 1-2 seconds -3x
5.) Move the Cursor relative from the Position if the Search was sucessfull 50pixel Down and 50pixel Right. 3x
6.) Output the WaitTime -3x

So i paste it into the Example and adding a new Hotkey F12 to get the difference between the Stretched Code without the function and the Reduced Code with using Function
Read the comments. (OLD Code without Functions --> F11 - Same Code Using Functions --> F12)




Function without Output / Input

If you dont want to Use Output or Input Variable. The Function is quite simple. There is nothing inside the Brackets. I take as an example a part from the Code above.

4.) If Found - Wait between 1-2 seconds -3x
5.) Move the Cursor relative from the Position if the Search was sucessfull 50pixel Down and 50pixel Right. 3x

I know, its not the best example (cause we have some inputvariables and its possible to avoid the repeat to put it behind or in front of the comparison )- but i hope you get the point how the structure is how you integrate Functions in your code. And i want to build up on this example.




Code: [Select all] [Expand] [Download] (Functions_().ahk)GeSHi © Codebox Plus







Function with Input Variables


Structure:

F_Name (Input1,Input2)
{
Output := Input1 + Input2
return Output
}


Try to Avoid MsgBox or other Visual Outputs inside Functions. It Stops the Script. For testing or debugging you a MsgBox is a good way to locate Issues inside the code.

Try to avoid Number inside Function. Use Imputs Variables to get the Script more Flexible

What i want to show in the next Function:

  • Function can used inside other Functions
  • String input the need quotation marks "Your String inside quotaion marks"





1.) F_Sleep_and_Move()
Function is now only for the Settings inside the function. So we add these parameters as Inputs that we can use this function flexible for every Movement and every defined time to wait.
So we create a the function:
F_Sleep_and_Move2(MoveX,MoveY,WaitMin,WaitMax)




F_Sleep_and_Move2(MoveX,MoveY,WaitMin,WaitMax) ;Output Sleep Time

{

Random, Wait , WaitMin, WaitMax
Sleep, % Wait

MouseMove, MoveX, MoveY, ,R

return Wait ; Output Value is the Variable behind return !

}




2.) We put the 3 First tasks into one Function - F_Compare_Color(X,Y,Colorinput,Colorname) and we enhance the Script with a string Input. There we can fill in the NameColor.

A String inside the Function Call need Quotation Marks

Example : F_Compare_Color(Color_Pink,"Pink")

1.)Get the Coordinates from the active Cursor position -1x
2.) Get the Color from the active Cursor position - 1x
3.) Compare with 3 Colors If Found the Color -3x

4.) + 5. ) F_Sleep_and_Move(MoveX,MoveY,WaitMin,WaitMax)
6.) Output the WaitTime -3x Via Message Box

So we add 2 new Functions to the code and implement it



F_CompareCoord_Color(X,Y,Colorinput,Colorname)

{
MouseGetPos, X_Pos,Y_Pos ; Get Mouse Coordinates
PixelGetColor, Color_OutputVar,X, Y ; Get the Color from Mouseposition

If ((X=X_Pos) & (Y_pos=Y)) ;Positioncheck
Status=found

; Comparison

If (Color_OutputVar = Colorinput) & (PinkPostionStatus=found)
{
F_Sleep_and_Move2(MoveX,MoveY,WaitMin,WaitMax)

return Colorname
;MsgBox, Colorname was Found Color:_%Color_OutputVar%
}

return NotFound
}







Code: [Select all] [Expand] [Download] (functions_(INPUT).ahk)GeSHi © Codebox Plus






Function with Output Variables


Now the final step. We modify the F_Compare_Color(Colorinput,Colorname) that we get the taken Coords out of the Function and the Color. So we get them out of the
If you want to do get a Variable out of a Function you have use the ByRef Parameter

New Function :
F_Compare_Color2(Colorinput,Colorname,ByRef CursorX,ByRef CursorY,ByRef CursorColor)

{
MouseGetPos, CursorX,CursorY ; Get Mouse Coordinates
PixelGetColor, CursorColor,CursorX, CursorY ; Get the Color from Mouseposition


; Comparison

If (CursorColor = Colorinput)
{
; F_Sleep_and_Move2(MoveX,MoveY,WaitMin,WaitMax) ;Possible - Use function in Function

return Colorname
;MsgBox, Colorname was Found Color:_%CursorColor%
}

return 0
}

I only changed the Names inside, because i want to have OutputVars that describe my Output.
The Value i give my ByRef Variables inside the function will create this variable (or override it) inside the code. So be careful here. Do not to choose a ByRef Variable what is allready is in use. (or you want to override it )

So here the Final Complete Code

Code: [Select all] [Expand] [Download] (Functions-Complete.ahk)GeSHi © Codebox Plus






Hope you get it all. But you will say now. The Long code without Functions is easier. Right. It is. But there are now so many methods to modifiy this script. Reuse it in other Project and add additional task you want.
I give you her some Task to modify the Script. Do it the with the use of functions and without it . You will notice quick the difference.

a.) Add more 5 Colors

Green beige = 0xCCC58F
Beige = 0xD1BC8A
Sand yellow =0xD2B773
Signal yellow =0xF7BA0B
Golden yellow = 0xE2B007

b.) add different Movements

White -> Move 6x 10 Pixel X+Y
Black -> Move 9x 5Pixel X+Y
Last edited by HinkerLoden on 31 Mar 2016, 06:03, edited 2 times in total.
User avatar
HinkerLoden
Posts: 93
Joined: 23 Mar 2016, 07:50
GitHub: HinkerLoden

Re: -- AHK BASICS --

29 Mar 2016, 22:18

Commando-list.ahk
(26.68 KiB) Downloaded 142 times




Commando Index sorted by Categories



Why ? Because the Help file and online faq is really without any Structure. They took everything and Order it alphabetic. Ok - the Content is a bit structured. But i think it is now much better find Commandos you need for you task.



Code: [Select all] [Expand] [Download] (Commando-List.ahk)GeSHi © Codebox Plus

Last edited by HinkerLoden on 02 Apr 2016, 23:36, edited 3 times in total.
User avatar
HinkerLoden
Posts: 93
Joined: 23 Mar 2016, 07:50
GitHub: HinkerLoden

Re: -- AHK BASICS --

30 Mar 2016, 03:35

Under Construction - Structuring the Order and clear out some Things. Maybe get a better visual overview

Code: [Select all] [Expand] [Download] (Expression-Operators.ahk)GeSHi © Codebox Plus

User avatar
HinkerLoden
Posts: 93
Joined: 23 Mar 2016, 07:50
GitHub: HinkerLoden

Re: -- AHK BASICS --

30 Mar 2016, 04:33

Built-in Variables

The following variables are built into the program and can be referenced by any script. With the exception of Clipboard, ErrorLevel, and command line parameters, these variables are read-only; that is, their contents cannot be directly altered by the script.
; ######################## ####################
;---------------------------------------------------------------------------
; ######################## ####################



Code: [Select all] [Expand] [Download] (built-in.ahk)GeSHi © Codebox Plus

User avatar
HinkerLoden
Posts: 93
Joined: 23 Mar 2016, 07:50
GitHub: HinkerLoden

Re: -- AHK BASICS --

30 Mar 2016, 12:13

Code: [Select all] [Expand] [Download] (Expression-Operators.ahk)GeSHi © Codebox Plus

User avatar
HinkerLoden
Posts: 93
Joined: 23 Mar 2016, 07:50
GitHub: HinkerLoden

Re: -- AHK BASICS --

31 Mar 2016, 06:50

Performance Template - With all descriptions for all possible cases / settings.

Code: [Select all] [Expand] [Download] (Performance-Template.ahk)GeSHi © Codebox Plus

Last edited by HinkerLoden on 03 Apr 2016, 16:05, edited 1 time in total.
User avatar
HinkerLoden
Posts: 93
Joined: 23 Mar 2016, 07:50
GitHub: HinkerLoden

Re: -- AHK BASICS --

31 Mar 2016, 06:51

Gui - Tutorial


MsgBox-Inputbox
Required the previous Tutorial

Little Practical Code Example. How to get Variables via Inputbox integrated in a loop. Maybe a bit hard for starters. But good Example for the practical usage.
But tell me if its really to hard to understand the Example.


Beginners should take a look on the following Lines:

1.) InputBox_Title := "InputBox_Title" . A_Index - OutputVar:= "Textonly" . A_Index ;Loop Up Buildin-Variable->A_Index ,

2.) InputBox, OutputVar, % %InputBox_Title%, % %Input... - Forced Expression with Percentage - Only the Name is Changed in the Loop.





Code: [Select all] [Expand] [Download] (MsgBox-InputBox.ahk)GeSHi © Codebox Plus

















Create Gui, Input/Output Handling (controlget,control,etc...), gLabel, Gui 2 data.ini transfer
Last edited by HinkerLoden on 01 Apr 2016, 02:55, edited 1 time in total.
User avatar
HinkerLoden
Posts: 93
Joined: 23 Mar 2016, 07:50
GitHub: HinkerLoden

Re: -- AHK BASICS --

31 Mar 2016, 06:52

Windows Environment - Open Windows/Programms - Read/ Get Information out of a window/control - Write / Edit a window
User avatar
HinkerLoden
Posts: 93
Joined: 23 Mar 2016, 07:50
GitHub: HinkerLoden

Re: -- AHK BASICS --

31 Mar 2016, 06:54

Input-Output - Hotkey Mouse and more Inputs,
User avatar
HinkerLoden
Posts: 93
Joined: 23 Mar 2016, 07:50
GitHub: HinkerLoden

Re: -- AHK BASICS --

01 Apr 2016, 03:46

Search algorithm - FastPixelSearch Options - Circle Search (Get direction from Postion) - Cone Search Based on Circle Search - LineFollower - ....
User avatar
nnnik
Posts: 2285
Joined: 30 Sep 2013, 01:01
Location: Germany

Re: -- AHK BASICS --

01 Apr 2016, 08:02

Wow this is getting big.
Recommends AHK Studio
User avatar
HinkerLoden
Posts: 93
Joined: 23 Mar 2016, 07:50
GitHub: HinkerLoden

Re: -- AHK BASICS --

02 Apr 2016, 04:12

GUI - Tutorial


Its a really complex Topic. But i try to Split it up in the Part where it get tricky. I dont want to make you here Crazy how to Create a Gui.
[url=viewtopic.php]Create a GUI is quite easy with the help from AutoGui.[/url]
If you want to add advanced Options or really need some special things,take a look on the Official Help.
Yes, this is really a mess. And i got myself really problems to understand the Interface. I allways took simple Message Boxes. But there come a point where you need more .

I only describe now part from the GUI which has a affect on the Coding. :!:
I dont explain how change colors and how to make it look pretty shiny. :crazy:


All Examples are collected in the Script at the End of the Tutorial.


So we take a look on a simple Gui.

Code: [Select all] [Expand] [Download] (Gui1.ahk)GeSHi © Codebox Plus



The Minimum to create Gui
1.)Gui, New --> Creates the Gui - one Line
2.)One - Gui add, ..... and sooooo much more
3.)Gui, Show --> Displays the Gui - one Line


Sure we have here a bit more, that i can show you a practical usage and some tricks how to handle things.

We take a closer look on the Gui Add controls. The important part is the addressing the Controls to Variables (vTheNameOfTheVariableYouWant) and the gLabels.
The Official Help :
Storing and Responding to User Input ¶

V: Variable. Associates a variable with a control. Immediately after the letter V, specify the name of a global variable (or a ByRef local that points to a global, or a static variable in v1.0.46.01+). For example, specifying vMyEdit would store the control's contents in the variable MyEdit whenever the Gui Submit command is used. If a control is not input-capable -- such as a Text control or GroupBox -- associating a variable with it can still be helpful since that variable's name serves as the control's unique identifier for use with GuiControl, GuiControlGet, and A_GuiControl. Note: Gui Submit does not change the contents of variables of non-input-capable controls (such as Text and GroupBox), nor certain others as documented in their sections (such as ListView and TreeView).

G: Gosub (g-label). Launches a subroutine or function automatically when the user clicks or changes a control. Immediately after the letter G, specify the name of the label to execute. gCancel may be specified to perform an implicit Gui Cancel (but if a label named "Cancel" exists in the script, it will be executed instead). The subroutine may consult the following built-in variables: A_Gui, A_GuiControl, A_GuiEvent, and A_EventInfo.


In the short Version

the vNameVariable decline the Variable from a Control Field - Cause we need them to return the result iniside Gui
the gNameLabel decline the Label from a Control Field - Cause we need them to store the Inputs or run a Subroutine.





In Relation for our Example we are able to trigger 4 different Subroutines. For a good reason. We need them. Normally all InputControls got a gLabel. To transfer the Value and run a Subroutine we need for our TAsk.
You can create maybe 10 Edit Fields without one gLabel and only use one Button. But it makes it more flexible. For the start these 2 things are important to know.



GUI ----> VAR

Get the Information out of the Gui happens with the Syntax GuiControlGet --> Official Help


RESULT/VAR ---> GUI

Put the Information into the Gui happens with the Syntax GuiControl --> Official Help
User avatar
HinkerLoden
Posts: 93
Joined: 23 Mar 2016, 07:50
GitHub: HinkerLoden

Re: -- AHK BASICS --

09 Apr 2016, 03:37

Really have problems , especially with the Basic Tut . Advices for more Examples or it contains allready to much. Its hard to get a combine a Practical Example without using to much enhanced code.

1. One StringInput Example 2. Loop Example with MouseMove


Code: [Select all] [Expand] [Download] (ArrowKeyShifter.ahk)GeSHi © Codebox Plus

BoBo
Posts: 1432
Joined: 13 May 2014, 17:15

Re: -- AHK BASICS --

15 May 2017, 04:01

Moin HinkerLoden (kerle, ich könnt mich stundenlang über deinen nickname beömmeln)

1st things first. R-E-S-P-E-K-T für deinen einsatz an der noob front !!! Much appreciated! 8-)

2tens. Mein englisch ist eher wackelig, und ich habe schon allein deshalb, und aus schierer neugier, vor kurzem [Grammarly] auf meinem rechner installiert. Dasamatotalcooldattool !!! Dazu gibts [hier] was auf die augen :idea:
Damit lässt sich manchertypisch "deutsche" flüchtigkeitsfehler (auch im browser!) recht gut abfangen: of/off, your/you're, on/at, ...
Schau mal drauf, ist bei der menge deiner ausführungen IMHO eine hilfreiche anwendung.

3tens. Freue mich mehr weiter von d'hier zu lesen :)

btw, Gruss auch an deinen eineiigen Zwilling HechterRoden ... MUAHAHAHAHAHA :lol:

PS. wenn du möchtest dann lösche ich den beitrag auch wieder (-> PM) damit er den fluss des tutorials nicht unterbricht !
PPS. ich bin auf der suche nach einem "template"-thread auf diesen beitrag gestoßen. Falls jemand ein template tool/script versteckt hält bitte melden. Thx :)

Return to “Tutorials”

Who is online

Users browsing this forum: No registered users and 3 guests