script file not found autohotkey что делать
Script file not found autohotkey что делать
I’m messing with a code that is called upon first time use of my script.
The problem specifically, is using file move on a running script.
After moving the running script followed by reloading it, I get a «Script File Not Found» error, due to the scripts directory being changed.
There is no documentation, or posts I’ve seen related to this issue, and I can not figure out a way to prevent this error/change to the new directory.
I thought SetWorkingDir was what I needed, but it does nothing?
Any help would be great, If needed I will post the related code.
Hey, thanks for the suggestion. That was actually one of the first things I tried yesterday, and it had bad results/was not reliable/loaded very slow often.
That seems like a bit of a cheap trick though anyways, if you know what I mean.
I’d like to do it properly if there is a better way. It seems like it should be a very basic thing, yet I can’t find any information about it.
Any other suggestions would be great, thanks.
Edit: I got it working properly now with that method. Just had to fix other conflicting code I had which was causing issues.
I’d still like to know if there is a more proper way to do this though. =d
I’m honestly surprised if that’s the only way, it seems like such a basic thing that ahk should be able to do. =/
Oh by the way, it does work fine performance wise now, I just had some other related code causing issues.
I appreciate you trying to help by the way!
I’ll show the related code, but it won’t really help to find a better solution in this situation. =/
Hey Punchin.
Thanks, I’ll look into this and post back after. It sounds like it’s what I’m looking for. I’ll try mess around a bit.
Edit: Now that I think of it.. This actually sounds more technical then running the new instance, followed by exiting the old instance.
My question- So it’s not possible to change the running scripts directory after FileMove, without reloading?
There’s no way to change the variable A_ScriptDir or use SetWorkingDir to do the above^?
Looks like I didn’t explain myself well enough. It’s slightly more technical of an issue than what you’re thinking.
I’m starting to think it’s probably not possible to do what I want. I edited my last post, but basically this is the question/issue.
So it’s not possible to change the running scripts directory after FileMove, without reloading?
There’s no way to change the variable A_ScriptDir or use SetWorkingDir to do the above^?
If the above is not possible, I guess I’ll have to stick with the easiest way.
What I ask is to simplify the problem, because we don’t have to overview over the complete ahk script(s). So for me it is not clear why SetWorkingDir is not working on your installation.
What I ask is to simplify the problem, because we don’t have to overview over the complete ahk script(s). So for me it is not clear why SetWorkingDir is not working on your installation.
Ok, SetWorkingDir does seem to work, but not exactly, or at least not how I thought it would.
This is the problem.
-I Move the file (running ahk script) to a specific folder with FileMove.
-I use SetWorkingDir to change the running scripts directory.
-I Reload the script, which then causes the error «Script File Not Found».
(Moving the running script to a different location causes the issue, and I thought using SetWorkingDir would solved the problem.)
Basically it tries to reload A_ScriptDir but the file has been moved/directory has changed, so A_ScriptDir is now invalid, and reload fails.
So the problem is I cannot change the A_ScriptDir variable to the new directory, and get passed the script file error.
I hope that better explains what I mean.
When using Script-Parameters call it with
run %A_AhkPath% «EO+ OFFICIAL.ahk» «skip», %EODir%
And check with
Hope this is a solution for you.
FoxHunter: Thanks for trying to help, I already understood all that though, and that’s not what I’m looking to do.
If Reload will fail no matter what after moving the running script (changing directory) that’s all I need to know.
If that’s the case, I’ll just run the new script followed by exiting the old, like I mentioned before.
I don’t understand why Reload fails though, I’d think you should be able to change the script directory, followed by reloading.
I’m pretty confused as to how it’s not possible to change the scripts A_ScriptDir variable. I thought SetWorkingDir was for this purpose, no?
What is the difference between A_ScriptDir and SetWorkingDir? Why can’t A_ScriptDir be changed/updated?
I understand that A_Script is a variable containing the running scripts directory.. Why doesn’t SetWorkingDir or anything else effect this?
Seems like a limitation in ahk that should not exist if that’s the case. =/
Logically, it should be very possible to change a running scripts directory to bypass this error from a running file being moved, and allow a reload. =/
Anyways, to clarify, if there is no way to move a running file, and update it’s directory to bypass a file error, and allow a reload, then that’s all I need to know.
Obviously there is nothing more I can do in that situation. =/
Punchin: I assign the OutputVar to another variable immediately, because I will be using that variable throughout the script. I’ll also be using multiple outputvar checks, so putting the OutputVar into a new variable for global use is required for me.
Edit: Sorry in advance if I don’t respond until late. I have work and other things to do today, so I may not reply back until very late tonight or tomorrow.
Appreciate all the attempts at helping, thanks!
shift+c:: will not be active because it does not exist in the current layout
Then it says: Error invalid key or button name, specifically: shift+c, then shows some lines of code and says at botton «The program will exit»
Quick start tutorial
To create a new script:
Save and close the file.
In Windows Explorer, double-click the script to launch it. A new tray icon appears.
Hold down the Windows key and press the spacebar. A web page opens in the default browser.
To exit or edit the script, right click its tray icon.
im talking about eddting the script that autoloads when i start AutoHotKey.
Guys. None of you are answering his question:
Guys. None of you are answering his question:
yes I did. he has been running AutoHotkey from the Start Menu. so he doesn’t know where the default script is to edit it. my Solution link mentions Notepad. to REALLY drive it home.
To Edit the Default AutoHotkey Script.
Guys. None of you are answering his question:
yes I did. he has been running AutoHotkey from the Start Menu. so he doesn’t know where the default script is to edit it. my Solution link mentions Notepad. to REALLY drive it home.
[list] To Edit the Default AutoHotkey Script.
JS, can I lift the list of links you posted and put it in my help thread? It’s well collected.
yes but only if they remain purple linked. hehehe. I love the look of my purple links. (you can click quote to be able to copy the list already purple linked, just remove the excess
Windows explorer? i have an internet explorer.
Those instructions on the tutorial should just say My Computer (not Windows Explorer) or something else (like My Documents). & it should tell you how to get there, like I do.
To create a new AutoHotkey (.ahk) Script.
Frequently Asked Questions (FAQ)
Table of Contents
Language Syntax
When are quotation marks used with commands and their parameters?
When exactly are variable names enclosed in percent signs?
Variable names are always enclosed in percent signs except in cases illustrated in bold below:
For further explanation of how percent signs are used, see Legacy Syntax and Dynamic Variables. Percent signs can also have other meanings:
When should percent signs and commas be escaped?
Literal percent signs must be escaped by preceding them with an accent/backtick. For example: MsgBox The current percentage is 25`%. Literal commas must also be escaped ( `, ) except when used in MsgBox or the last parameter of any command (in which case the accent is permitted but not necessary).
General Troubleshooting
What can I do if AutoHotkey won’t install?
7-zip Error: Use 7-zip or a compatible program to extract the setup files from the installer EXE, then run setup.exe or Installer.ahk (drag and drop Installer.ahk onto AutoHotkeyU32.exe).
AutoHotkey’s installer comes packaged as a 7-zip self-extracting archive which attempts to extract to the user’s Temp directory and execute a compiled script. Sometimes system policies or other factors prevent the files from being extracted or executed. Usually in such cases the message «7-zip Error» is displayed. Manually extracting the files to a different directory may help.
Setup hangs: If the setup window comes up blank or not at all, try one or both of the following:
Other: The suggestions above cover the most common problems. For further assistance, post on the forums.
Normally if AutoHotkey is installed, right-clicking an AutoHotkey script (.ahk) file should give the following options:
This can be done by applying this registry patch.
It may also be necessary to repair the default registry values, either by reinstalling AutoHotkey or by running AutoHotkey Setup (from the Start menu) and selecting apply near the top of the window.
Why do some lines in my script never execute?
Any lines you want to execute immediately when the script starts should appear at the top of the script, prior to the first hotkey, hotstring, or Return. For details, see auto-execute section.
Also, a hotkey that executes more than one line must list its first line beneath the hotkey, not on the same line. For example:
Why doesn’t my script work on Windows xxx even though it worked on a previous version?
There are many variations of this problem, such as:
If you’ve switched operating systems, it is likely that something else has also changed and may be affecting your script. For instance, if you’ve got a new computer, it might have different drivers or other software installed. If you’ve also updated to a newer version of AutoHotkey, find out which version you had before and then check the changelog and compatibility notes.
SoundGet, SoundSet, SoundGetWaveVolume and SoundSetWaveVolume behave differently on Vista and later than on earlier versions of Windows. In particular, device numbers are different and some components may be unavailable. Behaviour depends on the audio drivers, which are necessarily different to the ones used on XP. The soundcard analysis script can be used to find the correct device numbers.
Also refer to the following question:
How do I work around problems caused by User Account Control (UAC)?
User Account Control (UAC) is a common cause of problems, especially when moving from Windows XP/Vista/7 to Vista/7/8/10. Although it is present in Windows Vista and later, it is enabled by default on new systems or new installs, and it is more difficult to disable on Windows 8 and later.
By default, UAC protects «elevated» programs (that is, programs which are running as admin) from being automated by non-elevated programs, since that would allow them to bypass security restrictions. Hotkeys are also blocked, so for instance, a non-elevated program cannot spy on input intended for an elevated program.
UAC may also prevent SendPlay and BlockInput from working.
Common workarounds are as follows:
I can’t edit my script via tray icon because it won’t start due to an error. What do I do?
You need to fix the error in your script before you can get your tray icon back. But first, you need to find the script file.
Look for AutoHotkey.ahk in the following directories:
If you are running another AutoHotkey executable directly, the name of the script depends on the executable. For example, if you are running AutoHotkeyU32.exe, look for AutoHotkeyU32.ahk. Note that depending on your system settings the «.ahk» part may be hidden, but the file should have an icon like
You can usually edit a script file by right clicking it and selecting Edit Script. If that doesn’t work, you can open the file in Notepad or another editor.
If you launch AutoHotkey from the Start menu or by running AutoHotkey.exe directly (without command line parameters), it will look for a script in one of the locations shown above. Alternatively, you can create a script file (something.ahk) anywhere you like, and run the script file instead of running AutoHotkey.
How can I find and fix errors in my code?
For simple scripts, see Debugging a Script. To show contents of a variable, use MsgBox or ToolTip. For complex scripts, see Interactive Debugging.
Why is the Run command unable to launch my game or program?
Some programs need to be started in their own directories (when in doubt, it is usually best to do so). For example:
If the program you are trying to start is in %A_WinDir%\System32 and you are using AutoHotkey 32-bit on a 64-bit system, the File System Redirector may be interfering. To work around this, use %A_WinDir%\SysNative instead; this is a virtual directory only visible to 32-bit programs running on 64-bit systems.
Why are the non-ASCII characters in my script displaying or sending incorrectly?
Short answer: Save the script as UTF-8 with BOM.
Although AutoHotkey supports Unicode text, it is optimized for backward-compatibility, which means defaulting to the ANSI encoding rather than the more internationally recommended UTF-8. AutoHotkey will not automatically recognize a UTF-8 file unless it begins with a byte order mark.
In other words, UTF-8 files which lack a byte order mark are misinterpreted, causing non-ASCII characters to be decoded incorrectly. To resolve this, save the file as UTF-8 with BOM or add the /CP65001 command line switch.
To save as UTF-8 with BOM in Notepad, select UTF-8 from the Encoding drop-down in the Save As dialog.
Note that INI files accessed with the standard INI commands do not support UTF-8; they must be saved as ANSI or UTF-16.
Why do Hotstrings, Send, and Click have no effect in certain games?
Not all games allow AHK to send keys and clicks or receive pixel colors.
But there are some alternatives, try all the solutions mentioned below. If all these fail, it may not be possible for AHK to work with your game. Sometimes games have a hack and cheat prevention measure, such as GameGuard and Hackshield. If they do, there is a high chance that AutoHotkey will not work with that game.
Use SendPlay via the SendPlay command, SendMode Play and/or the hotstring option SP.
Note: SendPlay may have no effect at all on Windows Vista or later if User Account Control is enabled, even if the script is running as an administrator.
Increase SetKeyDelay. For example:
Try ControlSend, which might work in cases where the other Send modes fail:
Try the down and up event of a key with the various send methods:
Try the down and up event of a key with a Sleep between them:
How can performance be improved for games or at other times when the CPU is under heavy load?
If a script’s Hotkeys, Clicks, or Sends are noticeably slower than normal while the CPU is under heavy load, raising the script’s process-priority may help. To do this, include the following line near the top of the script:
My antivirus program flagged AutoHotkey or a compiled script as malware. Is it really a virus?
Although it is certainly possible that the file has been infected, most often these alerts are false positives, meaning that the antivirus program is mistaken. One common suggestion is to upload the file to an online service such as virustotal or Jotti and see what other antivirus programs have to say. If in doubt, you could send the file to the vendor of your antivirus software for confirmation. This might also help us and other AutoHotkey users, as the vendor may confirm it is a false positive and fix their product to play nice with AutoHotkey.
False positives might be more common for compiled scripts which have been compressed, such as with UPX (default for AutoHotkey 1.0 but not 1.1) or MPRESS (optional for AutoHotkey 1.1). As the default AutoHotkey installation does not include a compressor, compiled scripts are not compressed by default.
Common Tasks
Where can I find the official build, or older releases?
Can I run AHK from a USB drive?
How can the output of a command line operation be retrieved?
Testing shows that due to file caching, a temporary file can be very fast for relatively small outputs. In fact, if the file is deleted immediately after use, it often does not actually get written to disk. For example:
To avoid using a temporary file (especially if the output is large), consider using the Shell.Exec() method as shown in the examples for the Run command.
How can a script close, pause, suspend or reload other script(s)?
First, here is an example that closes another script:
To suspend, pause or reload another script, replace the last line above with one of these:
How can a repeating action be stopped without exiting the script?
To pause or resume the entire script at the press of a key, assign a hotkey to the Pause command as in this example:
To stop an action that is repeating inside a Loop, consider the following working example, which is a hotkey that both starts and stops its own repeating action. In other words, pressing the hotkey once will start the Loop. Pressing the same hotkey again will stop it.
How can context sensitive help for AutoHotkey commands be used in any editor?
How to detect when a web page is finished loading?
With Internet Explorer, perhaps the most reliable method is to use DllCall() and COM as demonstrated at www.autohotkey.com/forum/topic19256.html. On a related note, the contents of the address bar and status bar can be retrieved as demonstrated at www.autohotkey.com/forum/topic19255.html.
Older, less reliable method: The technique in the following example will work with MS Internet Explorer for most pages. A similar technique might work in other browsers:
How can dates and times be compared or manipulated?
To determine the amount of time between two dates or times, see EnvSub, which gives an example. Also, the built-in variable A_Now contains the current local time. Finally, there are several built-in date/time variables, as well as the FormatTime command to create a custom date/time string.
AutoHotkey Beginner Tutorial by tidbit
Table of Contents
Before we begin our journey, let me give some advice. Throughout this tutorial you will see a lot of text and a lot of code. For optimal learning power, it is advised that you read the text and try the code. Then, study the code. You can copy and paste most examples on this page. If you get confused, try reading the section again.
a. Downloading and installing AutoHotkey
Since you’re viewing this documentation locally, you’ve probably already installed AutoHotkey and can skip to section b.
Before learning to use AutoHotkey (AHK), you will need to download it. After downloading it, you may possibly need to install it. But that depends on the version you want. For this guide we will use the Installer since it is easiest to set up.
For a video instruction, watch Install and Hello World on YouTube.
b. How to create a script
Once you have AutoHotkey installed, you will probably want it to do stuff. AutoHotkey is not magic, we all wish it was, but it is not. So we will need to tell it what to do. This process is called «Scripting».
So now that you have created a script, we need to add stuff into the file. For a list of all built-in commands, function and variables, see section 5.
Here is a very basic script containing a hotkey which types text using the Send command when the hotkey is pressed:
We will get more in-depth later on. Until then, here’s an explanation of the above code:
For a video instruction, watch Install and Hello World on YouTube.
c. You cannot merge commands
When you are making your code, you might have the urge to put several commands on the same line or inside of each other, don’t. In section 5 we’ll talk about why it doesn’t work as you might expect and what you can do instead.
d. How to find the help file on your computer
There are a few ways to do this, I’ll assume you have it installed to the default locations:
What is a hotstring? Hotstrings are mainly used to expand abbreviations as you type them (auto-replace), they can also be used to launch any scripted action. For example:
The difference between the two examples is that the hotkey will be triggered when you press Ctrl + J while the hotstring will convert your typed «ftw» into «Free the whales».
Note: There are exceptions, but those tend to cause confusion a lot of the time. So it won’t be covered in the tutorial, at least, not right now.
A hotstring has a pair of colons on each side of the text you want to trigger the text replacement. While the text to replace your typed text goes on the right of the second pair of colons.
Hotstrings, as mentioned above, can also launch scripted actions. That’s fancy talk for «do pretty much anything». Same with hotkeys.
A nice thing to know is that you can have many lines of code for each hotkey, hotstring, label, and a lot of other things we haven’t talked about yet.
a. Keys and their mysterious symbols
Symbol | Description |
---|---|
# | Win (Windows logo key) |
! | Alt |
^ | Ctrl |
+ | Shift |
& | An ampersand may be used between any two keys or mouse buttons to combine them into a custom hotkey. |
(For the full list of symbols, see the Hotkey page)
Additionally, for a list of all/most hotkey names that can be used on the left side of a hotkey’s double-colon, see List of Keys, Mouse Buttons, and Joystick Controls.
You can define a custom combination of two (and only two) keys (except joystick buttons) by using & between them. In the example below, you would hold down Numpad0 then press Numpad1 or Numpad2 to trigger one of the hotkeys:
But you are now wondering if hotstrings have any cool modifiers since hotkeys do. Yes, they do! Hotstring modifiers go between the first set of colons. For example:
Visit Hotkeys and Hotstrings for additional hotkey and hotstring modifiers, information and examples.
b. Window specific hotkeys/hotstrings
Sometime you might want a hotkey or hotstring to only work (or be disabled) in a certain window. To do this, you will need to use either of these fancy commands with a # in-front of them:
These special commands (technically called «directives») create context-sensitive hotkeys and hotstrings. Simply specify a window title. But in some cases you might want to specify criteria such as HWND, group or class. Those are a bit advanced and are covered more in-depth here: The WinTitle Parameter & the Last Found Window.
To turn off context sensitivity for subsequent hotkeys or hotstrings, specify any #IfWin directive but leave all of its parameters blank. For example:
When #IfWin directives are never used in a script, all hotkeys and hotstrings are enabled for all windows.
The #IfWin directives are positional: they affect all hotkeys and hotstrings physically beneath them in the script. They are also mutually exclusive; that is, only the most recent one will be in effect.
For more in-depth information and similar commands, check out the #IfWinActive page.
c. Multiple hotkeys/hotstrings per file
This, for some reason crosses some people’s minds. So I’ll set it clear: AutoHotkey has the ability to have as many hotkeys and hotstrings in one file as you want. Whether it’s 1, or 3253 (or more).
The above code is perfectly acceptable. Multiple hotkeys, multiple hotstrings. All in one big happy script file.
d. Examples
So now you decided that you want to send (type) keys to a program. We can do that. Use the Send command. This command literally sends keystrokes, to simulate typing or pressing of keys.
But before we get into things, we should talk about some common issues that people have.
Just like hotkeys, the Send command has special keys too. Lots and lots of them. Here are the four most common symbols:
The gigantic table on the Send page shows pretty much every special key built-in to AHK. For example:
Caution: This table does not apply to hotkeys. Meaning, you do not wrap Ctrl or Enter (or any other key) inside curly brackets when making a hotkey.
An example showing what shouldn’t be done to a hotkey:
A common issue lots of people have is, they assume that the curly brackets are put in the documentation pages just for fun. But in fact they are needed. It’s how AHK knows that means «exclamation point» and not «press Alt «. So please remember to check the table on the Send page and make sure you have your brackets in the right places. For example:
To hold down or release a key, enclose the key name in curly brackets and then use the word UP or DOWN. For example:
But now you are wondering «How can I make my really long Send commands readable?». Easy. Use what is known as a continuation section. Simply specify an opening parenthesis on a new line, then your content, finally a closing parenthesis on its own line. For more information, read about Continuation Sections.
Note: There are several different forms of Send. Each has their own special features. If one form of Send does not work for your needs, try another type of Send. Simply replace the command name «Send» with one of the following: SendRaw, SendInput, SendPlay, SendEvent. For more information on what each one does, read this.
a. Games
This is important: A lot of games, especially modern ones, have cheat prevention software. Things like GameGuard, Hackshield, PunkBuster and several others. Not only is bypassing these systems in violation of the games policies and could get you banned, they are complex to work around.
If a game has a cheat prevention system and your hotkeys, hotstrings and Send commands do not work, you are out of luck. However there are methods that can increase the chance of working in some games, but there is no magical «make it work in my game now. « button. So try ALL of these before giving up.
There are also known issues with DirectX. If you are having issues and you know the game uses DirectX, try the stuff described on the FAQ page. More DirectX issues may occur when using PixelSearch, PixelGetColor or ImageSearch. Colors might turn out black (0x000000) no matter the color you try to get. You should also try running the game in windowed mode, if possible. That fixes some DirectX issues.
There is no single solution to make AutoHotkey work in all programs. If everything you try fails, it may not be possible to use AutoHotkey for your needs.
There are some other advanced features as well, such as command line parameters and CLSID. If you want to learn more about that stuff, visit the Run page.
Here are a few more samples:
For more in-depth information and examples, check out the Run page.
AutoHotkey has two main types of things used by the scripter to create code: Commands and functions.
A list of all commands and built-in functions can be found here.
Commands
You can tell what a command is by looking at its syntax (the way it looks). Commands do not use parentheses around the parameters like functions do. So a command would look like this:
When using commands, you cannot squish other commands onto the same line as a previous command (exception: IfEqual). You cannot put commands inside the parameters of other commands. For example:
Functions
As stated above, functions are different because they use parentheses. A typical function looks like:
Functions have a few main differences:
A function usually return a value differently than a command does. Commands need an OutputVar parameter, functions do not. The most common way assigning the value of a function to a variable is like so:
This isn’t the only way, but the most common. You are using MyVar to store the return value of the function that is to the right of the := operator. See Functions for more details.
a. Code blocks
Code blocks are lines of code surrounded by little curly brackets ( < and >). They group a section of code together so that AutoHotkey knows it’s one big family and that it needs to stay together. They are most often used with functions and control flow statements such as If and Loop. Without them, only the first line in the block is called.
In the following code, both lines are run only if MyVar equals 5:
In the following code, the message box is only shown if MyVar equals 5. The script will always exit, even if MyVar is not 5:
This is perfectly fine since the if-statement only had one line of code associated with it. It’s exactly the same as above, but I outdented the second line so we know it’s separated from the if-statement:
Variables are like little post-it notes that hold some information. They can be used to store text, numbers, data from functions and commands or even mathematical equations. Without them, programming and scripting would be much more tedious.
Variables can be assigned a few ways. We’ll cover the most common forms. Please pay attention to the equal sign ( = ).
Legacy text assignment
This is the simplest form for a variable, a legacy assignment. Simply type in your text and done.
Legacy variable assignment
Same as above, but you are assigning a value of a variable to another variable.
Legacy mixed assignment
A combination of the two legacy assignments above.
Expression text assignment
Expression variable assignment
In expression mode, variables do not need percent signs.
Expression number assignment
Thanks to expressions, you can do math!
Expression mixed assignment
A combination of the three expression assignments above.
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 percent signs:
When not to use percent signs:
b. Getting user input
Sometimes you want to have the user to choose the value of stuff. There are several ways of doing this, but the simplest way is InputBox. Here is a simple example on how to ask the user a couple of questions and doing some stuff with what was entered:
c. Other Examples?
Objects are a way of organizing your data for more efficient usage. Sometimes objects are referred to as arrays, but it’s important to note that all arrays are just objects. We call objects different things depending on what we are using them for, but all objects are the same.
An object is basically a collection of variables. The variable names are known as «Keys», and the contents of the variables are «Values».
When you hear people calling an object an array or indexed array, it usually means that all the keys are sequential numbers 1 and up. When you hear people calling an object an associative array, it means that the keys are either strings (text) or non-sequential numbers. Sometimes it’s a mix of both, and sequential numbers too!
There are no restrictions to what a key or value can be, and they can even be other arrays! When the values are arrays too, this is referred to as a nested array, and these will be explained later.
There are a number of reasons you might want to use an object for something. Some examples:
a. Creating Objects
There are a few ways to create an object, and the most common ones are listed below:
This will start you off with what is sometimes called an «indexed array». An indexed array is an object representing a list of items, numbered 1 and up. In this example, the value «one» is stored in object key 1 (aka index 1), and the value 17 is stored in object key 4 (aka index 4).
This is equivalent to the bracket syntax, but wrapped in a function.
This is equivalent to the brace syntax, but wrapped in a function.
It’s important to remember that every one of these definitions all create the same thing (objects), just with different keys.
b. Using Objects
There are many ways to use objects, including retrieving values, setting values, adding more values, and more.
To set values:
The same as above but with the dot notation.
To retrieve values:
This only lets you use literal strings for the keys. You cannot use variables in your keys with dot notation.
To add new keys and values:
To directly add a key and value, just set a key that doesn’t exist yet.
The same as above but with the dot notation.
Index is any integer key. This will shift ALL higher integer keys up by the number of values which were inserted, even if there are gaps (for example, only keys 1 and 100 exist, and you insert a value at key 50, it will shift 100 up to 101).
This «appends» the values to the end of the array MyObject. In other words, it inserts the values at the highest integer key plus one.
To remove keys and values:
This and the next methods below remove the key and the value. The previous value of MyObject[AnyKey] will be stored in RemovedValue.
Allows you to remove a range of numbered/integer or string keys between FirstKey and LastKey. The value it gives will be the number of keys that were removed, which is useful if you have a gap between your keys (e.g. you specify keys 1 through four, but key number 2 doesn’t exist, this will set NumberOfRemovedKeys to 3 as only three keys were there to be removed).
This removes the highest integer key, and returns the value. There are no keys higher than it to be affected.
We have reached the end of our journey, my good friend. I hope you have learned something. But before we go, here are some other things that I think you should know. Enjoy!
a. The mysterious square brackets
Throughout the documentation, you will see these two symbols ( [ and ] ) surrounding code in the yellow syntax box at the top of almost all pages. Anything inside of these brackets are OPTIONAL. Meaning the stuff inside can be left out if you don’t need them. When writing your code, it is very important to NOT type the square brackets in your code.
On the ControlGetText page you will see this:
So you could simply do this if you wanted:
Or add in some more details:
What if you wanted to use ExcludeTitle but not fill in WinText or WinTitle? Simple!
b. Finding your AHK version
Run this code to see your AHK version:
Or look for «AutoHotkey Help File» or «AutoHotkey.chm» in the start menu or your installation directory.
c. Trial and Error
Trial and Error is a very common and effective way of learning. Instead of asking for help on every little thing, sometimes spending some time alone (sometimes hours or days) and trying to get something to work will help you learn faster.
If you try something and it gives you an error, study that error. Then try to fix your code. Then try running it again. If you still get an error, modify your code some more. Keep trying and failing until your code fails no more. You will learn a lot this way by reading the documentation, reading errors and learning what works and what doesn’t. Try, fail, try, fail, try, try, try, fail, fail, succeed!
This is how a lot of «pros» have learned. But don’t be afraid to ask for help, we don’t bite (hard). Learning takes time, the «pros» you encounter did not learn to be masters in just a few hours or days.
d. Indentation
This stuff (indentation) is very important! Your code will run perfectly fine without it, but it will be a major headache for you and other to read your code. Small code (25 lines or less) will probably be fine to read without indentation, but it’ll soon get sloppy. It’s best you learn to indent ASAP. Indentation has no set style, but it’s best to keep everything consistent.
«What is indentation?» you ask? It’s simply spacing to break up your code so you can see what belongs to what. People usually use 3 or 4 spaces or 1 tab per «level».
See Wikipedia’s Indentation style page for various styles and examples. Choose what you like or learn to indent how you think it’s easiest to read.
e. Asking for Help
Before you ask, try doing some research yourself or try to code it yourself. If that did not yield results that satisfy you, read below.
If you don’t get an answer right away, wait at least 1 day (24 hours) before asking for more help. We love to help, but we also do this for free on our own time. We might be at work, sleeping, gaming, with family or just too busy to help.
And while you wait for help, you can try learning and doing it yourself. It’s a good feeling, making something yourself without help.