AutoHotkey tutorial – How to fill input fields on a website from a text file

AutoHotkey Tutorial - How to fill input fields from a text file - video
divider bar

In this AutoHotkey tutorial video, I will guide you through how you can fill the input fields on a website from a text file. The video covers the basics and could be useful for beginners since it’s really important how you can read a text file’s content.

divider bar

It is useful to know how you can read text files and work with them. A commonly preferred text file format is CSV ( Comma Separated Values ). At the beginning of the video, I created a text file with dummy data. Then I showed how can the delimiter character be replaced.  The old editor I used is AutoHotkey Studio, I started the project there. The next part was using FileRead. It is an important command that allows the user to read the text file’s content. It is followed by how actually reads AutoHotkey the text file using A_Index, and A_Loopfield commands. Then the field values of the file were assigned to variables and the script was finished.

; Script     AutoHotkey tutorial - How to fill input fields on a website from a text file.ahk
; Author:    Bence Markiel (bceenaeiklmr)
; Github:
; Date       01.05.2020

; #####################

#SingleInstance, Force
SendMode, Input
SetWorkingDir, %A_ScriptDir%
SetTitleMatchMode, 2

FileRead, Input, % A_ScriptDir "\" "input.txt"
WinActivate,   % "ahk_exe Chrome.exe"
WinWaitActive, % "ahk_exe Chrome.exe"
loop, Parse, Input, `n
    ; skip the header
    if (A_index=1)
    ; replace `n and split the into 'columns'
    Line := StrReplace(A_LoopField, Chr(13))
    Columns := StrSplit(Line, ";")
    ; assign variables
    FirstName := Columns.1
    LastName := Columns.2
    Email := Columns.3
    ; fix phone number (space, plus, and minus chars)
    RegExMatch(Columns.4, "\d+", Phone)
    ; click into the first field, some sleep is usually required
    Click, 128, 170
    Sleep, 100
    ; delete the field's content
    Send, {Delete}
    Sleep, 50
    ; send the values
    Send, % FirstName "{Tab}" LastName "{Tab}" Email "{Tab}" Phone
    Sleep, 10
divider bar

The AutoHotkey commands I used in this short script:

In case you need the Html file to test the script just copy the following code and save it with the Html file extension.

<!DOCTYPE html>
<h3>Fields tester</h1>
<form action=”/action_page.php”>
<label for=”fname”>First name:</label>
<input type=”text” id=”fname” name=”fname”><br><br>
<label for=”lname”>Last name:</label>
<input type=”text” id=”lname” name=”lname”><br><br>
<label for=”email”>Email address:</label>
<input type=”text” id=”email” name=”email”><br><br>
<label for=”phone”>Phone number:</label>
<input type=”text” id=”phone” name=”phone”><br><br>

Fields tester

divider bar
Forget Plugin - DIY


If you are interested in saving yourself a lot of time, check AHK.

Autohotkey is an automation tool, easy to learn, powerful!

You can check my favorite editors here.