Pages

2025/09/25

AutoHotkey (FREE) – Hold Down a Mouse Button with a Keyboard Shortcut on Windows 11

I don’t know the reason why people want to do this thing, it might be because of the computer screen is too big to drag something for too long. The script helps, just move the mouse, not holding anything.


I found the script here https://stackoverflow.com/questions/1993003/holding-down-the-left-mouse-button-in-autohotkey


The code is below.


F2::

alt := not alt

if (alt)

{

Click down

}

else

{

Click up

}

Return



Code explanation:

Pressing F2 (FN+F2) will hold down a left mouse button.


Usage: run the code (read how-to below), locate a mouse pointer where you want to drag it or do something else, press F2 then start dragging something. To cancel holding down, click a left click.


How to run the code.

1. Download AutoHotkey from https://www.autohotkey.com/



Click a button ‘Download’.



You will see there are 2 versions, I download both of them because some code can not be run with the old/new version.


Open the downloaded files and follow steps to install apps.


From my memories, you don’t have to open the apps because after installation is done, the apps will run in the background.


2. Copy the code above, open new document of Notepad, paste the code. You can change the first line to F2, F3…


Save it then add the extension .ahk.



To run the code, right click at .ahk file, then click the menu ‘Open’ near the icon ‘AutoHotkey’. (see the picture below)



You can see the script by clicking an arrow at the taskbar.



The code below is for holding down a right click button.


F3::Click % "right " (GetKeyState("RButton") ? "Up" : "Down")


Code explanation:

Pressing F3 (FN+F3) will hold down a right mouse button.


Usage: run the code (read how-to above), locate a mouse pointer where you want to drag it or do something else, press F3 then start dragging or something else. To cancel holding down, press F3 again.


You can change F3 to something else, such as F2,F4…


Important note: for 1st code, to cancel holding, just click a left click button.

For 2nd code, to cancel holding, press F3 again.


I tested 2nd code with Gesturefy (Firefox add-on) by setting a right click button as a target button to be held for performing gestures. It works fine.

 

No comments: