Pass-Through Hotkey Combinations to Prevent Shortcut Blocking (AutoHotkey Tip)

Sometimes You Want AutoHotkey Hotkeys to Block Other Program Shortcuts While Other Times You Want Both to Work

One of the effects of AutoHotkey Hotkeys includes blocking action for key combinations in Windows and other programs. While often desirable, occasionally you want both the Hotkey and the program shortcut to work. To do this we put a squiggle (tilde prefix ~) in front of the Hotkey combination.

In the MouseMeasure.ahk app, use the cursor keys (Right, Left, Up, Down) to move the mouse cursor one pixel at a time for accurate placement of both ends of the graphic measurement line. Delete to clear the line and ToolTip.

When I added the Arrow keys to the MouseMeasure.ahk script as Hotkeys for precisely locating the mouse cursor onscreen, it triggered the undesirable side effect of blocking the text cursor movement associated with those same keys in editing screens. By placing a tilde (~) in front of each Hotkey, I can accomplish both accurate mouse cursor placement in the invisible GUI and continue using text cursor movement in an editing window without disabling or closing the MouseMeasure.ahk app. (See “Replace Hotkeys with the AutoHotkey GetKeyState() Function” for an introduction to the GDIPlus version of the script. See “How to Draw Lines with AutoHotkey Using Windows GDIPlus Graphics” for information on the GDIPlus functions used in the script.)

When to Use Hotkey Pass-through … or Not!

Library Benefits

As a rule, I don’t implement Hotkey pass-through using the tilde (~) unless I discover a reason not to block other program or Windows shortcuts. Allowing Hotkeys to pass-through and work in the currently active process can cause unpredictable or unwanted effects.

If I find that I’ve used a Hotkey which interferes or blocks important native shortcuts in other programs, I usually change the Hotkey. Some key combinations, such as Ctrl+C, Ctrl+V, Ctrl+Z, etc., I consider sacred. If I want to use a close relative to one of those key combos, then I add the Alt, Shift, or Win key (or a combination of them) to the Hotkey. I only resort to making the Hotkey combination fall-through to the currently active app if the situation calls for it.

The MouseMeasure.ahk script presents a few of those situations where pass-through Hotkeys only make sense. The invisible MouseMeasure.ahk markup GUI covers the entire screen—unseen to both the eye and most mouse/keyboard action. While I don’t recommend maintaining the distance-measuring utility loaded at all times, you can operate almost any other program simultaneously without even noticing the active MouseMeasure.ahk app—unless you activate the gauging line using Ctrl+LButton.

Using the Tilde Prefix (~) in the MouseMeasure.ahk Script

Since I always find accurately locating the mouse cursor by hand a little iffy, I added the Arrow keys as pixel-level navigation for exact placement—not unlike the MousePrecise.ahk script. I also defined the Delete key as a Hotkey for erasing any active line and measurement from the screen. Both the cursor (Arrow) keys and the Delete key provide the most intuitive techniques for implementing these options. People will likely test these keys without any prior instruction:

Up::MouseMove, 0, -1, 0, R  ; UpArrow hotkey => Move cursor upward
Down::MouseMove, 0, 1, 0, R  ; DownArrow => Move cursor downward
Left::MouseMove, -1, 0, 0, R  ; LeftArrow => Move cursor to the left
Right::MouseMove, 1, 0, 0, R  ; RightArrow => Move cursor to the right
Delete::
		active_Draw:=0
		setTimer updatePos, off
		SetTimer,DrawStuff,off
		ToolTip
		Gdip_GraphicsClear(GdipOBJ.G)
		UpdateLayeredWindow(GdipOBJ.hwnd, GdipOBJ.hdc)
Return

However, when I first added the above precise mouse cursor location Hotkeys to the script using the Arrow keys, I could no longer move the text cursor with those same keys in an editing window—a standard technique for text navigation in most word processing apps. The Hotkeys blocked any text cursor action. Plus, the use of the Delete key to clear the graphic line blocked letter deletion in editing windows.

To resolve these problems, I merely placed a tilde in front of each Hotkey allowing the native program action of the Hotkey to pass-through to the currently active window.

~Up::MouseMove, 0, -1, 0, R  ; UpArrow hotkey => Move cursor upward
~Down::MouseMove, 0, 1, 0, R  ; DownArrow => Move cursor downward
~Left::MouseMove, -1, 0, 0, R  ; LeftArrow => Move cursor to the left
~Right::MouseMove, 1, 0, 0, R  ; RightArrow => Move cursor to the right
~Delete::
		active_Draw:=0
		setTimer updatePos, off
		SetTimer,DrawStuff,off
		ToolTip
		Gdip_GraphicsClear(GdipOBJ.G)
		UpdateLayeredWindow(GdipOBJ.hwnd, GdipOBJ.hdc)
Return

Now, when I use the MouseMeasure.ahk app, I can both accurately place the start and endpoint of the measurement line and use the arrow keys to move the text cursor in the active editor just under the invisible GUI. Each keyboard action functions at the same time. I get a similar effect with the Delete key—although, I recently moved the Delete Hotkey to the inside the #If directive conditional to block the Delete key native function in other programs during line drawing.

Click the Follow button at the top of the sidebar on the right of this page for e-mail notification of new blogs. (If you’re reading this on a tablet or your phone, then you must scroll all the way to the end of the blog—pass any comments—to find the Follow button.)

jack

This post was proofread by Grammarly
(Any other mistakes are all mine.)

(Full disclosure: If you sign up for a free Grammarly account, I get 20¢. I use the spelling/grammar checking service all the time, but, then again, I write a lot more than most people. I recommend Grammarly because it works and it’s free.)

Find my AutoHotkey books at ComputorEdge E-Books!

Find quick-start AutoHotkey classes at “Robotic Desktop Automation with AutoHotkey“!

2 thoughts on “Pass-Through Hotkey Combinations to Prevent Shortcut Blocking (AutoHotkey Tip)

  1. Thank you! Finally, an explanation about hotkeys and pass through that makes sense. I have struggled with that rule for years, but now I see the light.

    Like

  2. The keyboard precision is awesome. Much better than just mouse and don’t have to zoom in for accuracy and strain the hand or lose the calibration. Edge detection would be great future add on maybe using the pixel search function? Even get volume off three consecutive measurements. Amazing where you can take this. Looking forward and learning a lot through these steps. Thanks Jack!

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s