Branch: master
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
145 lines (103 sloc) 3.76 KB
layout author title date desc img imgdesc extras categories tags toc
Wouter Van Schandevijl
Autohotkey Use Case: Submitting a Form
2019-01-30 16:00:00 -0800
Wait, how did you just fill in that form? Autohotkey, that's how!
Automate repetitive tasks with Autohotkey!
desc url
Test Form Html Page
title icon
Autohotkey Use Case

A simple Autohotkey use case you can start using in your application right away:
Filling in an entire form with predefined values.

The Use Case

The Form

Considering the following login form (Html version)


The Script

The Autohotkey script:


Type `lma` (Short for `Login Mega App`?) while the cursor is in the email input to fill in the form and submit it.

Autohotkey installation

  • Download and install Autohotkey (Pick Autohotkey 1.1)
  • Create a file with the extension ahk
  • Paste the Autohotkey code from above in the file
  • Double click your newly created file to activate the hotstring
  • Press lma while the cursor is in the email input on the test page

To start with Windows

To start your Autohotkey script with Windows put a file shortcut in your startup folder.

To get to this directory:

  • Press Windows + E
  • Press Control + L
  • Type shell:startup
  • Press Enter

Usually something like:

C:\Users\your_user_name\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup

With your_user_name: $env:USERNAME (PS1) or %USERNAME% (CMD)

More info

The Script Explained

; `*` means the hotstring will expand as soon as it is typed in
; It can be omitted so the hotstring will only expand when followed by an `EndChars`
; The part between the double :: is the key sequence that will trigger the hotstring

; Send some text

; Send special characters
SendInput {tab}{tab}{space}{tab}{enter}

Using a hotstring instead

The same could also be triggered by pressing Control + Windows + L for example


See the blog post on hotkeys for more hotkey info and possibilities.

Context sensitive

When testing an application, I tend to use a different browser for each user profile so that I do not have to logout/login all the time. We could even check the value of document.title and use different credentials for different applications.

; Type loginAdv to activate the hotstring
WinGetTitle, title, A

; These logins work only in Chrome
#IfWinActive, ahk_class Chrome_WidgetWin
    IfInString, title, ProjectDocumentTitle1
        SendInput admin{tab}pwd{enter}
    Else IfInString, title, ProjectDocumentTitle2
        SendInput superuser{tab}pwd{enter}
        SendInput root{tab}pwd{enter}

; Firefox
#IfWinActive, ahk_class MozillaWindowClass
    IfInString, title, ProjectDocumentTitle1
        SendInput client{tab}pwd{enter}
    Else IfInString, title, ProjectDocumentTitle2
        SendInput clerk{tab}pwd{enter}
        SendInput guest{tab}pwd{enter}