Send key without triggering custom hotkey Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
pneumatic
Posts: 338
Joined: 05 Dec 2016, 01:51

Send key without triggering custom hotkey

Post by pneumatic » 18 Jan 2022, 09:06

Hello, I am trying to Send {Browser_Back} without it triggering my custom Browser_Back:: hotkey -- is it possible?

I've tried the $ prefix , different Send modes and #InstallKeybdHook, without success.

My script looks like this:

Code: Select all

Browser_Back::
;do conditonal stuff
return

Browser_Back Up::
; do conditional stuff,
; including a conditional Send {Browser_Back}
; without triggering Browser_Back::
return
My goal is to use Browser_Back downstroke as a custom modifier to turn my touchpad into a scroll wheel when swiping up/down.

On the upstroke of Browser_Back, it will check if the touchpad was touched, and if not, then I want to just Send a normal Browser_Back, otherwise I'd lose the usage of that button (which I use frequently).

If you're wondering why the heck someone would want to do this since most touchpads have two finger scrolling, the answer is that it's a Logi K400 which can be comfortably gripped when holding it in your lap in a HTPC setting where you use only your thumb to control the touchpad, meaning that to two-finger scroll would require changing grips every time you wanted to scroll. Basically I am writing a script so that I can access all my common functions without having to change my grip of the keyboard at all.

Thanks & AutoHotkey is incredible -- prefer it to the Logi Options software.

User avatar
mikeyww
Posts: 27020
Joined: 09 Sep 2014, 18:38

Re: Send key without triggering custom hotkey

Post by mikeyww » 18 Jan 2022, 09:20

Perhaps:

Code: Select all

#IfWinActive ahk_exe chrome.exe
^F3::Send !{Left}
#IfWinActive

pneumatic
Posts: 338
Joined: 05 Dec 2016, 01:51

Re: Send key without triggering custom hotkey

Post by pneumatic » 18 Jan 2022, 09:26

Thanks, but I'm not sure how that would be useful.

The Browser_Back key is a physical button on the keyboard, and I'll be using it as a custom modifier to enable touchpad scrolling in all applications, not just web browsing.

I may even end up using a different key to Browser_Back, such as Escape or even the ~ key. Regardless, the problem is that I can't figure out how to send that key without triggering its hotkey subroutine (otherwise I lose that key's native function).

User avatar
mikeyww
Posts: 27020
Joined: 09 Sep 2014, 18:38

Re: Send key without triggering custom hotkey

Post by mikeyww » 18 Jan 2022, 09:42

I am confused about your goal. Perhaps a step-by-step example would help. You want to press the key but not trigger the hotkey with the key's name? I do not understand.

swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: Send key without triggering custom hotkey

Post by swagfag » 18 Jan 2022, 09:46

a down/up hotkey pair is always implemented with hook hotkeys by default, so ahk-sending the downkey from the upsubroutine wont trigger the downsubroutine

if u observe other behaviors, either that isnt ur script or something else is at play

pneumatic
Posts: 338
Joined: 05 Dec 2016, 01:51

Re: Send key without triggering custom hotkey

Post by pneumatic » 18 Jan 2022, 09:50

mikeyww wrote:
18 Jan 2022, 09:42
I am confused about your goal. Perhaps a step-by-step example would help. You want to press the key but not trigger the hotkey with the key's name? I do not understand.
I would like to Send {Browser_Back} without triggering my custom defined Browser_Back:: hotkey routine.

I may not necessarily use Browser_Back though, I may use Escape instead. But I'd still like to be able to Send {Escape} without triggering my custom Escape:: hotkey routine.

eg. many applications require usage of the Escape key, so if I had no way of sending an Escape key event, I wouldn't be satisfied with this.

User avatar
mikeyww
Posts: 27020
Joined: 09 Sep 2014, 18:38

Re: Send key without triggering custom hotkey

Post by mikeyww » 18 Jan 2022, 09:53

My script shows how you can use Ctrl+F3 to go back in the browser's history. You could change the hotkey. If you want to use a hotkey for multiple actions, you can add conditional statements to indicate the context. If you already have a hotkey routine for Esc, then you can modify it to indicate when the "back" sequence should be sent. Another approach is below. This sets the context for when a different action should occur.

Code: Select all

Esc::MsgBox, test ; Default action
#IfWinActive ahk_exe chrome.exe
Esc::Send !{Left} ; If Chrome is active, go back in the browser's history
#IfWinActive
Another approach is below.

Code: Select all

c::Send a
#InputLevel 1
a::Send b
#InputLevel 0

User avatar
boiler
Posts: 17021
Joined: 21 Dec 2014, 02:44

Re: Send key without triggering custom hotkey

Post by boiler » 18 Jan 2022, 10:15

pneumatic wrote: I may not necessarily use Browser_Back though, I may use Escape instead. But I'd still like to be able to Send {Escape} without triggering my custom Escape:: hotkey routine.

eg. many applications require usage of the Escape key, so if I had no way of sending an Escape key event, I wouldn't be satisfied with this.
You said that using $ didn't work for you, but that doesn't make sense. Perhaps you had a separate script running that was triggered by pressing Esc. In that case, the $ wouldn't prevent that other script's hotkey from triggering. To test it, close all other scripts and run the following script. The Esc up hotkey sends Esc without triggering the Esc orEsc up hotkey subroutines. It should be the same with your Browser_Back key as well.

Code: Select all

$Esc::ToolTip, Esc was pressed

$Esc up::
	ToolTip
	MsgBox, About to send Esc
	Send, {Esc}
return

pneumatic
Posts: 338
Joined: 05 Dec 2016, 01:51

Re: Send key without triggering custom hotkey

Post by pneumatic » 18 Jan 2022, 10:16

swagfag wrote:
18 Jan 2022, 09:46
a down/up hotkey pair is always implemented with hook hotkeys by default, so ahk-sending the downkey from the upsubroutine wont trigger the downsubroutine

if u observe other behaviors, either that isnt ur script or something else is at play
Ok, I found the cause of my confusion: I was using a Soundplay, *16 to notify me when a hotkey had fired, and when I released the key I heard the sound effect, however that was due it it still buffering the SoundPlay event making it seem like the upstroke was causing it. Swapping SoundPlay for ToolTip reveals the Send {Escape} is not in fact calling my Escape:: hotkey.

However it does not send an Escape key to Windows either, so I'm still losing the functionality of the Escape key and need some way around that -- maybe I could send a custom keycode to get around that?

Mikey's solution of sending a !{Left} seems to be a good workaround in lieu of {Browser_Back}, but I may not end up using Browser_Back as my hotkey, so I'd still like some way of sending the key's default function to Windows -- surely this has got to be possible. It can't be that as soon as you define a hotkey in AHK, that you lose the ability to send that key to Windows. I refuse to believe AHK would have such a limitation and I must be doing something wrong.

User avatar
mikeyww
Posts: 27020
Joined: 09 Sep 2014, 18:38

Re: Send key without triggering custom hotkey

Post by mikeyww » 18 Jan 2022, 10:20

I haven't yet seen a step-by-step explanation of all of the specific functionality that is needed. We are just seeing bits and pieces here. Perhaps you have not yet decided exactly what should happen?
Last edited by mikeyww on 18 Jan 2022, 10:20, edited 1 time in total.

User avatar
boiler
Posts: 17021
Joined: 21 Dec 2014, 02:44

Re: Send key without triggering custom hotkey  Topic is solved

Post by boiler » 18 Jan 2022, 10:20

pneumatic wrote: However it does not send an Escape key to Windows either, so I'm still losing the functionality of the Escape key and need some way around that -- maybe I could send a custom keycode to get around that?
You should be able to use Send, {Esc} and have it still work. Try the script I posted above and see if the Esc that is sent when you click OK on the MsgBox that appears after releasing the Esc key actually sends an Esc that is recognized by whatever you are expecting to recognize it. Make sure any other scripts you have running that may interfere are closed.

pneumatic
Posts: 338
Joined: 05 Dec 2016, 01:51

Re: Send key without triggering custom hotkey

Post by pneumatic » 18 Jan 2022, 10:23

Thanks, look like I must have screwed something up elsewhere, as creating a new .ahk file with just the following code works fine and sends the Browser_Back to Windows on release and does NOT trigger the Browser_Back:: again -- sorry for wasting all your time.

Code: Select all

Browser_Back::
ToolTip , Browser_Back pressed
return

Browser_Back Up:: 
ToolTip , Browser_Back released
Send {Browser_Back}
return

Post Reply

Return to “Ask for Help (v1)”