• Become a Power user Intro to AutoHotkey Intermediate AutoHotkey Intermediate Objects GUIs are Easy w/AutoHotkey Painlessly switch from V1 to V2

AutoHotkey Webinar- Recursion (Having a function call itself)

In this AutoHotkey webinar we cover Recursion (having a function call itself over and over)

Video Hour 1: High-level overview: Hour 1

Video Hour 2: Q&A: Hour 2

AutoHotkey Webinar 03/2019 Hour 1- Recursion

AutoHotkey Webinar 03/2019 Hour 1- Recursion

Recursion is a powerful function that can simplify complex tasks and allow for easier adaptation to changes in programming, demonstrated through examples in AutoHotkey.

  • 00:00 📚 The speaker discusses recursion and his work on developing an application called quick access using AutoHotkey, expresses gratitude for the opportunity to share, and mentions a book that should have focused more on specific tasks in Python.
    • Joe Klein introduces guest presenter Jean elan, who discusses recursion and his work on developing an application called quick access using autohotkey and other languages.
    • The speaker expresses gratitude for the opportunity to share and discuss with Joe and his group, and mentions a book that Massimo hasn’t read but loves.
    • The book “Automate the Boring Stuff with Python” should have focused more on specific tasks and how to accomplish them in Python rather than just providing a general overview of the language.
    • During the webinar, participants were instructed to use the chat function to ask questions, raise their hand, or unmute themselves when necessary, and the speaker mentioned that they have been doing podcasts with Jackie.
    • The recent videos discussed the uses and limitations of AutoHotkey for newcomers, and there was a reminder about a hot stream.
    • The speaker discusses the possibility of organizing a gathering in Las Vegas in 2020 for AutoHotkey enthusiasts to network, learn from each other, and potentially have qualified speakers, and asks for interest and participation from the audience.
  • 06:37 📝 Recursion is a powerful function that calls itself and is useful for tasks like looping over files and folders, demonstrated through an example of building and using a file structure.
    • The speaker discusses the possibility of implementing a system similar to the one described in the video in a casino in Vegas.
    • The speaker showcases a Tetris game written in AutoHotkey, highlighting its functionality and simplicity.
    • Recursion is a function that calls itself and is useful for tasks such as looping over files and folders or crawling websites when the depth is unknown.
    • Recursion is demonstrated through an example of building and using a file structure, with the concept illustrated by an image of a woman holding a cup of tea inside a box, which contains another box with a similar image.
  • 11:55 🔄 Recursion is the invocation of a function within itself, allowing for simplified tracking of progress and understanding of complex tasks.
    • Recursion is the invocation of a function within itself, and although it may create an infinite loop, it can be controlled by implementing an exit point in the code, and it is important to understand functions before using recursion.
    • AutoHotkey has built-in functions like string lens that return the length of a string, and you can create your own custom functions that process values within the function and have local variables.
    • Variables with the same name inside and outside a function are not affected by each other, which is important to understand when using recursion, as each recursive call creates new instances of the variables.
    • Go down the stairs, collect garbage on each sublevel, and repeat until there are no more stairways going down, then go back up and collect all the garbage on the top floor.
    • Recursion is a process where steps are repeated in different contexts, such as scanning folders and files, and it is necessary to keep track of the hierarchical structure.
    • Using recursion can simplify the process of keeping track of progress and understanding what is happening when performing a task, even if it may initially seem complex.
  • 19:21 📝 The speaker discusses the concept of recursion in relation to navigating through folders and collecting files, demonstrating how to use recursion to build a menu with submenus in AutoHotkey.
    • There are multiple folders with subfolders and files, and the speaker discusses the concept of recursion in relation to connecting and processing these files.
    • The process involves navigating through different levels and folders, collecting files until there are no more subfolders, and then returning to the root folder to process any remaining folders until everything has been scanned and collected.
    • We will go step by step through our folder structure, gathering files and building a string that will display in a GUI, and then we will use recursion to build a menu with submenus.
    • Local variables are not lost after each function ends, they are still accessible within the function and can be used across different instances of the function.
    • The speaker demonstrates that the AutoHotkey built-in command “loop files” with the “R” option can be used to create a list of files in a folder and its subfolders, eliminating the need to create recursive functions, but also explains that a more complex approach using recursion allows for a better understanding of how recursion works.
    • The speaker demonstrates the use of a command that utilizes indentation to display results, specifically in the context of calling a function to scan files.
  • 28:06 📝 Understanding recursion simplifies programming and allows for easier adaptation to changes, as demonstrated by the example of adding or removing floors in a building.
    • Understanding recursion simplifies programming and allows for easier adaptation to changes, as demonstrated by the example of adding or removing floors in a building.
    • The speaker explains how a variable called “int level” is used to track the number of sub levels and create indentation in the content.
    • The code can have multiple levels of recursion, and by using the debugger, we can track the steps and go deeper into sublevels and then back to the main level.
    • Create a route variable, call the recursive function, and use a tooltip to inform the user of the progress when running the function on a large set of folders and files.
    • Create indentation at the first level with a variable value of zero.
  • 34:06 🔍 A program searches for files in folders, adds their names to a result string, and repeats the process for multiple files, demonstrating recursion in AutoHotkey.
    • The speaker discusses how a program searches for files in folders, adding their names to a result string, and repeats the process for multiple files.
    • The speaker discusses incrementing a variable and looking for folders, appending content to a variable, and returning the content of a subfolder.
    • The speaker demonstrates the process of recursion in AutoHotkey, showing how the function enters new instances and builds an indentation string with a value of 1.
    • Create a string of file paths in a folder, including subfolders, and increment the level variable while checking for additional subfolders.
    • The speaker demonstrates a recursive function that collects file names from subfolders and returns the accumulated list of file names.
    • The speaker explains the process of recursively scanning folders and collecting their contents, demonstrating it with a GUI.
  • 44:18 📝 The speaker demonstrates how to use recursion in AutoHotkey to scan folders and display the contents in a GUI, explaining the logic of scanning directories and looping through folders, creating menus and submenus, and utilizing the Z key for navigation.
    • The speaker demonstrates how to use recursion in AutoHotkey to scan folders and display the contents in a GUI.
    • The speaker explains the process of adding the results from lower levels to the content already obtained from upper levels in order to create indentation, and discusses the logic of scanning directories and looping through folders.
    • The logic is the same whether it is a file or a folder, as the program loops through each item and goes to a lower level if it is a directory, otherwise it processes the item.
    • The speaker explains how to create menus and submenus in AutoHotkey, including options for selecting icons, actions, and shortcuts.
    • The Z key is crucial for recursion as it indicates where to return after completing a sublevel, and in this example, it is used to navigate through different menu levels and execute specific actions.
    • Create a string with structured text that can be split into an array using the string split function.
  • 55:05 📝 Recursion in AutoHotkey allows for building menus and submenus, making it easy to modify and rearrange the menu structure, and can be helpful for debugging and solving complex problems like scanning HTML.
    • The speaker explains how to use recursion in AutoHotkey to build menus and submenus.
    • The speaker demonstrates the process of adding items and submenus to a main menu using recursion in AutoHotkey.
    • When selecting items from a menu, different actions can be called and labeled, making it easy to modify and rearrange the menu structure.
    • Using the debugger in AutoHotkey can be helpful for troubleshooting and ensuring that variables have the correct content, especially when working with recursion, although it can only show the variables of the current instance of the function.
    • Recursion can be helpful for debugging and solving complex problems, such as building menus, by allowing you to step through code and execute specific sections without having to go through the entire script.
    • Recursion can be used to scan HTML and it is more powerful to use functions for recursion because variables can be isolated and shared within sublevels.

AutoHotkey Webinar 03/2019 Hour 2- Recursion Q&A

AutoHotkey Webinar 03/2019 Hour 2- Recursion Q&A

The key idea of the video is that AutoHotkey is a powerful tool for automating tasks in Excel and other programs, and it can save time and improve efficiency in various applications.

  • 00:00 📝 The speaker discusses recursion and its applications, and invites participants to share their recent work or ask questions.
    • The speaker discusses recursion and its applications, and invites participants to share their recent work or ask questions.
    • The speaker created a script to automate the process of checking URLs on a page and received positive feedback from colleagues.
    • If you can’t see the toolbar at the bottom of the Zoom window, try clicking on “more” or logging in through the Zoom program instead of a browser to be able to share your screen.
  • 04:07 🎙️ The speaker discusses using AutoHotkey to automate tasks in Excel, including putting a time stamp in a spreadsheet and triggering macros, and explains the similarities between AutoHotkey syntax and another program’s syntax.
    • The speaker discusses a macro for putting a time stamp into a spreadsheet and suggests using a VBA script if it is embedded in Excel.
    • The speaker discusses the similarities between autohotkey syntax and the syntax of another program, and mentions the existence of built-in hotkeys and a file they made with default hotkeys for Windows and Office.
    • The speaker discusses using a spreadsheet in AutoHotkey and how it detects the current row and allows for manual interruption.
    • The speaker discusses using AutoHotkey to trigger a macro in Excel instead of manually pressing a hotkey.
    • The speaker demonstrates how to trigger a subroutine instead of using a hotkey inside a VBA module.
    • The speaker discusses converting the simplicity of a subroutine in Excel into AutoHotkey code.
  • 14:36 🎥 The speaker demonstrates how to use AutoHotkey to manipulate and customize data in Excel, including connecting to the active window, recording macros, and troubleshooting issues, providing a time-saving alternative to macro files.
    • The speaker discusses using Excel in AutoHotkey to connect to the active window and retrieve data, demonstrating how to modify the code to achieve the desired format.
    • The speaker demonstrates how to manipulate input data in Excel using AutoHotkey, showing that it is possible to adjust and customize the process without relying on VBA.
    • The speaker discusses the use of functions in AutoHotkey scripts to handle different levels of Excel worksheets and demonstrates how to record a macro in Excel.
    • The speaker demonstrates how to use AutoHotkey to bold text in Excel and troubleshoots issues with running the macro.
    • Learn how to easily write and adapt Excel macros using the Macro recorder and AutoHotkey, which can save time and eliminate the need for macro files, while also providing a function library for various Excel tasks.
    • Dale is having trouble with his microphone during the webinar.
  • 32:31 🔍 Ahmed seeks help with image search on his new computer, the speaker recommends using the “fine text” function and suggests checking out a tutorial for more information.
    • Ahmed is having trouble with image search on his new computer and is seeking help to search for a specific image and click on it within a designated area.
    • The speaker recommends using the “fine text” function, which is not a built-in function but can be used to quickly and easily search for text without having to save the file, and suggests checking out a tutorial or video for more information on how to use it.
    • The speaker discusses using an image search in AutoHotkey, finding it more reliable and easier to work with, and offers assistance to someone struggling with their code.
    • The speaker discusses issues with a floppy disk drive being recognized as a system boot-up drive in Windows.
    • The speaker discusses the importance of allowing for a small allowance of variation in code when using images for screen replication, and suggests using a number between 0 and 255 to indicate the level of variation desired.
    • The speaker demonstrates how to use the find text function in AutoHotkey to search for specific text or images on the screen and manipulate them accordingly.
  • 44:41 📝 The speaker demonstrates a function that searches for text and executes an action if found, discusses the convenience of Fine text, compares image search and find text functions in AutoHotkey, and suggests experimenting with settings for color and gray variation.
    • The speaker demonstrates a function that searches for text and executes an action if the text is found, with the option to continuously run the function in a loop.
    • The speaker discusses the convenience of not having to save files on the computer, but mentions that some settings in the tool are not clearly documented.
    • Fine text has a GUI that allows for easy customization and converts image data into text, making it a useful tool for simple tasks.
    • Image search and find text are both functions in AutoHotkey, but find text is easier to use and allows for more specific customization, while image search requires learning and using image resources outside of the script.
    • Image search in AutoHotkey can find anything on your screen, but it may require tweaking the settings, and using find text is a faster and more reliable option, although it may not work well with sensitive information, and when distributing the script, the image data is included in the plain text code.
    • The speaker discusses the difficulty of knowing which number to tweak in order to achieve the desired variation in color and gray, and suggests that experimenting with different settings may be necessary.
  • 54:31 🔍 Using AutoHotkey for personal use is a great tool, with the speaker discussing the usefulness of built-in options and the issue of coordinates affecting the click function.
    • Using AutoHotkey for personal use without customizing the settings is a great tool that works well for the speaker.
    • The speaker discusses a GUI for image searches and the usefulness of built-in options, such as color variations, in AutoHotkey.
    • The speaker discusses using the screen as a reference point for Image Search instead of a specific window, as the code does not make a window active.
    • The speaker discusses the variation of pixels and how it affects the functionality of the program, suggesting a potential solution to display a message box when a pixel is found.
    • The issue with the image search and click command was that the coordinates were set to absolute coordinates on three monitors, causing the click to be off target.
    • Set the mouse coordinates and target type correctly to ensure the click function works properly in the script.
  • 01:05:10 🔧 There were syntax issues and default settings not being reflected, but using AutoHotkey helped troubleshoot and understand the code; there was a bug in the macro creator and a workaround was suggested; a tool for building scripts in AutoHotkey was mentioned but may not be actively developed.
    • There is a syntax issue causing the code to not run properly, and the default settings are not being reflected on the right side.
    • Instead of using the click function, the speaker suggests using the mouse move function for easier control, but there may be some issues with different types of clicks.
    • Using AutoHotkey makes it easier to troubleshoot and understand the code by using message boxes and stepping through it.
    • The speaker discusses an issue with a button not being clicked due to a bug in the macro creator, and suggests a workaround by recording and copying the click action.
    • There was an extra comma in the code, but when the speaker tried to add it manually, it didn’t work because the software hadn’t been updated.
    • The speaker discusses their experience with using a tool for building scripts in AutoHotkey, mentioning that it was useful but may no longer be actively developed.
  • 01:15:56 📝 Notepad++ is a useful tool for AutoHotkey programming, providing features like parameter highlighting and easier tracking of commas, while Visual Studio Code is recommended for programming in multiple languages, including AutoHotkey, with its intellisense feature for Python; the speaker thanks attendees and promises to send scripts and recordings.
    • Notepad++ is a useful tool for AutoHotkey programming as it provides helpful features such as parameter highlighting and easier tracking of commas in functions or commands.
    • The speaker discusses the benefits of using Visual Studio Code as an editor for programming in multiple languages, including AutoHotkey, and mentions the usefulness of its intellisense feature for Python.
    • The speaker thanks everyone for attending the webinar and mentions that they will send out a copy of the scripts and recordings to the participants.

 


Script HighlightTetris from maestrith

Normally we have a more work-related type script but I thought this was a great example of other things that can be done with AutoHotkey.  You can get the script from maestrith’s github account. Pretty cool that it is only ~640 lines.

AutoHotkey Vegas Convention

We also mentioned some of us are considering putting together a convention in Las Vegas.  At a high level we’re thinking:

  • Network with peers and people of like mind
  • Attend in-person training to focused seminars
  • Hackathon (get into groups and have multiple solutions to a goal)

If you’re interested, please fill out this form and we’ll keep in touch as things develop

Recursion in AutoHotkey

Jean Lalonde, author of Quick Access Popup, did a great job leading us through creating recursive functions in AutoHotkey.

Click here to get Jean’s deck & AutoHotkey files .

Over-simplifying things, while doing a recursive function remember you

  1. have a function which does something
  2. the function will check if it needs to go deeper (call itself)
  3. the function will check to see if it has finished (so it will back-out to top)