How do I make Auto Hotkey do Alt+F4 when I press right mouse button and scroll wheel?

8,649

I want a script in Auto Hotkey so that I can press Alt+F4 by pressing the right mouse button and scroll wheel. How do I do this?

If you haven't already done so, download and install AutoHotkey.

Looking at this basic overview on AutoHotkey hotkeys and this more complete key list, you can see:

  • Alt is represented by either ! or LAlt / RAlt (assuming you might want to trigger a specific Alt key).

  • F4 is represented by F4.

  • The right mouse button is represented by RButton.

  • The scroll wheel is represent by WheelDown, WheelUp or MButton. The first two assume the wheel is being "scrolled" and the last one assumes the scroll wheel is being "clicked".

  • AutoHotkey has a Send function to send keystrokes.

  • Hotkey combinations sometimes include & to bind two keys together.

  • Braces {} are necessary to Send keys with names that could also be typed (e.g. {Enter}, {Delete}, etc.).

Lastly, through observation, it can be determined that hotkey sequences and their respective script commands are typically separated by a double colon ::.

Armed with this information, you can now make a script. Since AutoHotkey script files are just simple text documents, your first step will be to open Windows Notepad. Next, putting together the information above, you might type something like:

MButton & RButton::Send !{F4}

You can then save this file with an .ahk extension (rather than .txt) to associate it with AutoHotkey. To start the saved script, simply double-click it (note that this assumes you installed AutoHotkey normally and it isn't already running).

Using the example script above, you could then (hypothetically) press the middle mouse button (scroll wheel), then the right mouse button and this would send Alt+F4.


Caveats

  • The first button you list is the prefix key (the button you press first to start a hotkey sequence). In this case, if we use the right mouse button first, this can interfere with normal right-click operations. Therefore, the middle mouse button should be listed/pressed first.

  • Regarding the right mouse button, while it is possible to use a tilde ~ in front of a key to send the original keypress (i.e. the normal function won't be blocked), this really doesn't seem to work correctly for your scenario.

  • Scroll wheel clicks can be fidgety on cheaper mice. If you have a mouse with extra buttons (such as a gaming mouse), you may wish to use one of those buttons instead.

  • Buttons sent with AutoHotkey are generally still sensitive to window focus. If you are using Alt+F4 to bring up the Windows shutdown menu, this may be something to consider.


Share:
8,649
skillz21
Author by

skillz21

Updated on September 18, 2022

Comments

  • skillz21
    skillz21 over 1 year

    My question is simple, I want a script in Auto Hotkey so that I can press Alt+F4 by pressing the right mouse button and scroll wheel. How do I do this?