Keyboard shortcut to insert date using AutoHotkey V2

3 min read 7 hours ago
Published on Jan 20, 2025 This response is partially generated with the help of AI. It may contain inaccuracies.

Table of Contents

Introduction

This tutorial will guide you through creating a global keyboard shortcut using AutoHotkey V2 to quickly insert the current date and/or time into any program on Windows. Many applications have their own shortcuts for this function, which can be difficult to remember. By using AutoHotkey, you can set up a simple, customizable solution to streamline your workflow.

Step 1: Install AutoHotkey V2

  1. Visit the AutoHotkey website.
  2. Download the latest version of AutoHotkey V2.
  3. Run the installer and follow the prompts to complete the installation.

Step 2: Create a New Script

  1. Open a text editor (such as Notepad).
  2. Create a new file and save it with a .ahk extension, for example, InsertDate.ahk.
  3. This file will contain the script for your hotkey.

Step 3: Write the Script

  1. Open your newly created script file in the text editor.
  2. Enter the following code to set up the hotkey for inserting the date:
    ; Define a hotkey for inserting the current date
    ^d::  ; Ctrl + D
    FormatTime, CurrentDate,, yyyy-MM-dd  ; Change format as needed
    SendInput %CurrentDate%
    return
    
    • This code uses Ctrl + D as the hotkey. You can change ^d to another key combination if desired.
    • The FormatTime function is used to format the date. Modify the format string to customize how the date appears.

Step 4: Save and Run the Script

  1. Save your changes to the script file.
  2. Double-click the .ahk file to run the script.
  3. You should see an AutoHotkey icon in your system tray, indicating that the script is active.

Step 5: Test the Hotkey

  1. Open any text editor or application (like Notepad or Word).
  2. Press your defined hotkey (e.g., Ctrl + D) to insert the current date.
  3. Check that the date appears correctly in your document.

Step 6: Customize for Time

  1. To also insert the current time, you can modify the script. Add the following code:
    ^t::  ; Ctrl + T
    FormatTime, CurrentTime,, HH:mm:ss  ; Change format as needed
    SendInput %CurrentTime%
    return
    
    • This code uses Ctrl + T as the hotkey for time. Adjust as needed.

Step 7: Run the Script on Startup (Optional)

  1. To have your script run automatically on Windows startup:
    • Press Win + R to open the Run dialog.
    • Type shell:startup and hit Enter.
    • Create a shortcut to your .ahk script file in the Startup folder.

Conclusion

With these steps, you have successfully created a global keyboard shortcut to insert the current date and time using AutoHotkey V2. This can enhance your productivity by allowing you to quickly input date and time information in any application. Feel free to explore additional AutoHotkey features to further customize your workflow!