Integrating AI into Windows (a low-tech approach with AutoHotKey)
Wouldn’t it be nice if you could press a shortcut and ask ChatGPT about something you see on your screen? Or select a bit of text in any application, press a shortcut, and have ChatGPT explain what it means?
In this post I’ll show you how to set up these two interactions.
To be clear, what I describe below doesn’t allow you to achieve anything you couldn’t do before, it just makes it easier; it makes it feel like your favourite Chatbot is integrated right into the operating system, rather than having to copy/paste between windows.
These instructions are for Windows, Chrome and ChatGPT, but you can apply the same logic to get the job done with different tools.
Setup
AutoHotKey
First, install AutoHotKey (apologies if you don’t like doing that sort of thing, I too avoided it for a few decades).
This is a tool that allows you to write scripts that run in response to a keyboard shortcut.
Next, create a file anywhere (e.g. your documents folder) called shortcuts.ahk
. Leave it empty for now.
This file will define the keyboard shortcuts and the scripts that run in response to them. To make the file ‘active’ you can double click it, but if you want these shortcuts always available, you’ll want the file to run on startup. So:
- Copy the
shortcuts.ahk
file. - Press
Win
+R
, typeshell:startup
and hitEnter
. This will open your startup directory. Everything in here is executed when Windows starts. - Hold down
shift
and right click in a blank area (this gives you the hard-core right-click menu) and select Paste shortcut. - Now double-click the shortcut to test that it launches AutoHotKey — you should see an H icon show up in your taskbar. If you hover, it should say ‘shortcuts.ahk’.
If so, AHK is working, ready for us to define some shortcuts. But first…
Chatbot as a window
As we write the scripts below, we’ll need a way to bring up an AI chatbot window. If your preferred chatbot comes as a Windows app, great, if not we’ll ‘install’ the website.
Depending on which chatbot you use, you might see a little Install button on the right of the URL bar. For example, to install Claude there’s a button:
Otherwise you might need to click on the snowman buttons in the top right of the browser and go to Save and share > Install page as app…
When asked if you’d like to pin the app to your taskbar, click Yes.
Now you should have your chatbot installed so it behaves like a Windows app.
Note that if you drag the pinned icon into the first position in your taskbar (just to the right of the start button), you can open it with Windows
+ 1
. This works for other numbers and positions too. This is one way to open the app with a shortcut.
If you don’t want to pin the app to your taskbar, or rely on its position, you can give it a shortcut like so:
- Right click its icon in the taskbar.
- In the right click menu, right click the app name (right click inception)
- Click Properties
- In the dialog that appears, define a shortcut in the Shortcut key box and click OK.
With that done, we’ll be able to open the chatbot window with a shortcut.
OK, let’s get to the shortcut scripts. You can edit the shortcuts.ahk
file in any text editor. If you’ve got IntelliJ or VS Code, I’d suggest installing the AutoHotKey plugin to get syntax highlighting.
To avoid clashing with shortcuts in other apps, I like to use The Holy Trinity of ctrl
+ alt
+ shift
, and preferably use a key close to these so I can reach them all with my left hand.
With that in mind, I’ll use ctrl
+ alt
+ shift
and:
A
to Ask ChatGPT about some textS
to Show ChatGPT part of the screen
Asking about selected text
Here’s the plan:
- When you press the shortcut
ctrl
+alt
+shift
+a
, AHK will run a little script. - That script will first copy to the clipboard whatever text was already selected.
- Then it will see if the ChatGPT app is running, and if so, switch to it and focus the input box.
- If it’s not running, it will launch it.
- Then it’ll paste from the clipboard and append the word ‘explain’.
OK, open up the shortcuts.ahk
file and paste in the following:
; Key shortcuts
; ^ = Control
; ! = Alt
; + = Shift
; # = Windows
; Ask ChatGPT about the selected text
^!+a:: ; ctrl + alt + shift + a
{
Send("^c") ; Copy the selected text to the clipboard
Sleep(100)
; If the ChatGPT window is open, activate it
SetTitleMatchMode(3) ; Full match when using WinExist
if (WinExist("ChatGPT")) {
WinActivate
Send("+{Esc}") ; Focus the input
Sleep(100)
} else {
; Else we'll have to open it
; Ctrl+Alt+Shift+Win opens Office 365! So wait for ctrl to be released
KeyWait("Control")
Send("#1") ; Where 1 is the taskbar position
Sleep(2000) ; Wait for the app to load
}
Send("“^v” - explain")
}
A few things to note:
- Comments start with semicolons. Gross.
- You might need to fiddle with the
Sleep
values for your machine, they’re in milliseconds. - The folks over at Microsoft decided that
ctrl
+alt
+shift
+Win
should open Microsoft Office 365 (one can only assume that mind-altering drugs were involved). AHK will trigger theWin
+1
key combo before the original shortcut keys (includingctrl
,alt
andshift
) are released, meaning that Office 365 opens! So we wait forctrl
to be released before sending the Windows key. - You don’t need to use a shortcut to launch the ChatGPT window, you could also do something like
Run(“C:\Users\USER_NAME\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Chrome Apps\ChatGPT”)
, pointing to the location where the ‘app’ was installed. I just figured if you’re reading this you’re kinda into shortcuts so would want it that way. shift
+esc
is a shortcut that the ChatGPT folks have in their front end to focus the input box (stealing the shortcut from Chrome’s task manager). Other chatbots might automatically focus the text input box and not require this.- This script pastes the selected text in curly braces and appends the word ‘explain’. Having just a single word means that if I want to type something else here, I can press
ctrl
+shift
+←
and type over the word ‘explain’, and if I want it to explain a particular word in a paragraph, I can just append that word.
To activate the above script (once saved), right click the AHK taskbar icon and select Reload Script. Or, if you’re using IntelliJ with the plugin, you can run the file from within the IDE (play button at the top left of the file) and that has the same effect. If it asks you if you want to replace the existing running script, click Yes.
Now to test that it’s working, select any text anywhere and hit ctrl
+ alt
+ shift
+ a
and it should show up as a prompt in your chatbot of choice. If something goes wrong, fiddle with the sleep values.
Now, on to the second interaction…
Showing ChatGPT an area of the screen
In the same shortcuts.ahk
file, paste the following below what you’ve already got:
; Show ChatGPT a screenshot
^!+s:: ; ctrl + alt + shift + s
{
; Ctrl+Alt+Shift+Win opens Office 365! So wait for ctrl to be released
KeyWait("Control")
Send("#+s") ; Win + shift + s to open Snip tool
Sleep(100)
; Wait for user to capture screen area
while !(GetKeyState("LButton", "P"))
Sleep(10)
while (GetKeyState("LButton", "P"))
Sleep(10)
Sleep(500)
; If the ChatGPT window is open, activate it
SetTitleMatchMode(3) ; Full match when using WinExist
if (WinExist("ChatGPT")) {
WinActivate
Send("+{Esc}") ; Focus the input
Sleep(100)
} else {
; Else we'll have to open it
Send("#1") ; Where 1 is the taskbar position
Sleep(2000) ; Wait for the app to load
}
Send("+{Esc}") ; Focus the input
Send("^v")
Send("explain")
}
A few notes:
- This is mostly the same logic as the first script, but instead of sending
ctrl
+c
to copy the selected text, it uses the built-in Windows shortcutWin
+shift
+s
to capture an area of the screen. I’m pretty sure this always copies the image to the clipboard, but if not, open the Snip app and look for a setting to make it do this. - After calling this shortcut, we then need to wait for the mouse button to go down then up again while you draw a rectangle to select an area of the screen to capture.
- Then we repeat the logic to focus ChatGPT and paste.
Save and reload the script, as before.
Now to test that it’s working, press ctrl
+ alt
+ shift
+ s
, click and drag to select an area of the screen, and that image should show up in ChatGPT with the word ‘explain’.
I use this quite a lot. For example if I see some code in a YouTube video and want to run it, I’ll just press ctrl
+ alt
+ shift
+ s
, draw a box around the code and tell ChatGPT to “type this out”. Same for any case of ‘images of text’ where I want the text, like URLs in a slideshow in a video (“make this a link”), or just pictures of interesting things where I want to know what the interesting thing is (“what’s on that person’s head?”). Oh and this is great for those error message windows with an error code that you can’t copy to the clipboard.
Now, there’s a bit of duplication in this code with the logic to ‘focus or open ChatGPT’. I don’t want to write a whole AutoHotKey tutorial, but I’ll leave you with a version of the full file that extracts the repeated code out into a function.
#Requires AutoHotkey v2.0-
; Key shortcuts
; ^ = Control
; ! = Alt
; + = Shift
; # = Windows
GoToChatGPT() {
; If the ChatGPT window is open, activate it
SetTitleMatchMode(3) ; Full match when using WinExist
if (WinExist("ChatGPT")) {
WinActivate
Send("+{Esc}") ; Focus the input
Sleep(100)
} else {
; Else we'll have to open it
; Ctrl+Alt+Shift+Win opens Office 365! So wait for ctrl to be released
KeyWait("Control")
Send("#1") ; Where 1 is the taskbar position
Sleep(2000) ; Wait for the app to load
}
}
; Ask ChatGPT about the selected text
^!+a:: ; ctrl + alt + shift + a
{
Send("^c") ; Copy the selected text to the clipboard
Sleep(100)
GoToChatGPT()
Send("“^v” - explain")
}
; Show ChatGPT a screenshot
^!+s:: ; ctrl + alt + shift + s
{
KeyWait("Control")
Send("#+s") ; Win + shift + s to open snip tool
Sleep(100)
; Wait for user to capture screen area
while !(GetKeyState("LButton", "P"))
Sleep(10)
while (GetKeyState("LButton", "P"))
Sleep(10)
Sleep(500)
GoToChatGPT()
Send("+{Esc}") ; Focus the input
Send("^v")
Send("explain")
}
; Bonus shortcut: search Google for the selected text
^!+x:: ; ctrl + alt + shift + x
{
Send("^c")
Sleep(100)
Run("https://www.google.com/search?d&q=" . A_Clipboard)
}
Well, I hope that’s useful to at least one human out there, have a noice day.