How to use AutoHotKey to execute scripts quering AIs with a single mouse button click

AutoHotkey 2.0 enables sophisticated automation workflows by binding custom scripts to hardware inputs. Among countless other things, this can create seamless integration between peripheral devices and web-based AI interfaces through keystroke interception and URL automation. The approach described in this article leverages the script's hotkey system to map mouse button events to chat AI queries. 

Explanation of the workflow

AutoHotkey v2 scripts can execute chat AI queries through URL automation and web browser integration, enabling rapid access to specific AI assistance workflows. The core implementation involves creating hotkey functions that open browser tabs with pre-constructed query parameters—for example, "grok.com?q=ask something" launches Grok with the prompt "ask something".

AutoHotKey scripts can leverage clipboard control to capture selected text and append contextual prompts before submitting to AI services.
 
I personally like mice with many programmable buttons. I program the mouse buttons to execute specific keyboard strokes (like Ctrl + Alt + P, for example) and I bind those keyboard strokes to the AutoHotKey scripts.

So the workflow in my case is:

Select text or url → Mouse button clicked → Mouse manufacturer's software executes some keyboard combination → AutoHotKey script that's hooked to that keyboard combination is executed → The script opens a new browser tab and inserts a specific AI's url passing the currently selected text in the url.

So, for example, we can type "how much is 2 * 24?", select this text, then press a mouse button, and AutoHotKey will open a new browser tab with the following url: "grok.com?q=how much is 2 * 24?" and press Enter for us. Then, of course, we will see Grok AIs page with the "how much is 2 * 24" query already sent and Grok's reply to us.

Installing AutoHotkey 2.0 on Windows

Installing AutoHotkey v2 requires downloading the official installer from autohotkey.com, which provides the AutoHotkey_2.0.xx_setup.exe file.

Creating the scripts and adding them to the Startup folder so that they will be activated with each Windows start

Now when we have AutoHotKey 2.0 installed, we will create 3 scripts that will
  1. Ask Grok AI to write a summary of the text (article) that can be found by the selected URL
  2. Ask 5 different AIs any (same) question
  3. Send the selected question just to Grok AI (when we don't want to use the previous script to ask all 5 AIs)
Navigate to

c:\Users\<YourUserName>\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup\

If you don't want to manually navigate to this folder you can open 

%APPDATA%\Microsoft\Windows\Start Menu\Programs\Startup

or press Win + R and run "shell:startup".

Create 3 files in the Startup folder:

1) "Give summary in AI.ahk" with the following content:
#Requires AutoHotkey >=2.0

^!p:: ; The script will be hooked to Ctrl + Alt + P (^ = Ctrl, ! = Alt, p = p :)) )
{
	Send "^c" ; Execute Ctrl + C to copy selected text into clipboard
	Sleep 100 ; wait 100ms before proceeding, to make sure the text has been copied by now
	SendInput "^t" ; Execute Ctrl + T to open a new browser tab
	; The next to lines will type "grok.com?q=Give a short (but not too short, at least
	; half a page) summary: " followed by Ctrl + V (which will insert the previously 
	; selected text from the clipboard), followed by Enter to open the url
	SendText "grok.com?q=Give a short (but not too short, at least half a page) summary: "
	SendInput "^v{Enter}"
}
2) "Search selected text in AIs.ahk" with the following content:
#Requires AutoHotkey >=2.0

^!i:: ; Bind the script to Ctrl + Alt + I
{
	SendInput "^c" ; copy selected text to clipboard
	Sleep 100 ; wait until it has been copied
	
	; GROK
	SendInput "^t" ; open new browser tab
	; Type "grok.com?q=" followed by pressing Ctrl + V to insert the selected text, followed
	; by Enter to open Grok’s page
	SendText "grok.com?q="
	SendInput "^v{Enter}"
	
	; PERPLEXITY
	SendInput "^t"
	SendText "https://www.perplexity.ai/search/new?q="
	SendInput "^v{Enter}"
	
	; CHATGPT
	SendInput "^t"
	SendText "https://chatgpt.com/?q="
	SendInput "^v{Enter}"
	
	; COPILOT (based on chatgpt)
	SendInput "^t"
	SendText "https://www.bing.com/search?showconv=1&sendquery=1&mode=creative&q="
	SendInput "^v{Enter}"
	
	; GEMINI
	SendInput "^t"
	SendText "https://www.google.com/search?udm=50&q="
	SendInput "^v{Enter}"
}
3) "Search in Grok.ahk" with the following text inside:
#Requires AutoHotkey >=2.0

^!m:: ; Bind the script to Ctrl + Alt + M
{
	SendInput "^c" ; copy selected text to clipboard
	Sleep 100 ; wait until it’s been copied
	
	; GROK
	SendInput "^t" ; open new browser tab
	; Type "grok.com?q=" followed by pressing Ctrl + V to insert the selected text, 
	; followed by Enter to open Grok’s page
	SendText "grok.com?q="
	SendInput "^v{Enter}"
}

Let's run these scripts right now to load and activate them. Just run them as you would any executable. They will also be activated automatically after each restart.

Testing the scripts

Now let's test the scripts. Open your web browser, type "how much will be 2 * 12?", select it and press Ctrl + Alt + I. AutoHotKey should now open 5 new tabs with different AIs and in each tab you should see the answer "24".

Now let's test the other script. Open some news article, select the full url and press Ctrl + Alt + P. AutoHotKey should open Grok, asking it to provide the summary and Grok should give you the requested summary.

Finally, select "how much will be 2 * 12?" text in the browser and press Ctrl + Alt + M. AutoHotKey should open Grok, passing the question and receiving the correct reply.

Final step (optional) - bind the scripts to mouse buttons.

If you don't want to bind scripts to mouse buttons, you can simply execute the scripts by pressing keyboard combinations. But, as I said earlier, I personally like to execute my scripts with the many buttons I have on my mouse. All manufacturers that make mice with many programmable buttons provide software to program the mouse buttons.

I will use Razer Synapse here as an example.

In case you've already loaded the script, we need to unload them now, or they will interfere with button programming. To unload, find them in the system tray, right-click on each one and select Exit.

Now let's open Razer Synapse and open the mouse control panel (by selecting the mouse)



Select the button you want to program. Then navigate to the Keyboard Function on the left, and select Key Recording in the dropdown. Now press the desired combination (in our case it's Ctrl + Alt + I or Ctrl + Alt + P) and click Save.

Again, just to remind, now, when we click the programmed mouse button it will be the same as if we press Ctrl + Alt + P, and our AutoHotKey script is hooked to Ctrl + Alt + P.


Do the same for the 2nd script/button & 3rd script/button.

Let's test it. Load the scripts (they were unloaded to be able to program the mouse buttons to the same key combinations as the scripts ). In your browser, select some text or url, press the mouse button you've just programmed. It should execute the script.

That's it! Have fun!

Hope you found the article useful. Let me know in the comments if you want me to share more of my scripts.

Comments

Popular posts from this blog

How to set up a simple backup on your UGREEN NAS using rsync & cron scheduler

How to connect to your UGREEN NAS via SSH

Fixing low brightness (darkness) in 4K HDR movies