"CTRL + mousebutton 4" to send a key

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
S1lver
Posts: 23
Joined: 07 Nov 2020, 04:14

"CTRL + mousebutton 4" to send a key

10 Mar 2022, 14:22

Hello guys. I've spent 4 hours on google, and i cannot find a solution to how I make a script where Ctrl + mousebutton4 sends a key. I hope you can guide me if i send you my tiny script which looks like:

Code: Select all

^XButton2::

While GetKeyState("^XButton2","p")
{
send {g down}
sleep 100
send {g up}
}
return
[Mod edit: [code][/code] tags added.]
------------
the "^" sign suppose to be CTRL but nothing happens when I hold down the CTRL plus the mousebutton. it's very frustrating 🙂
Hardcoder
Posts: 278
Joined: 19 Feb 2022, 13:13
Location: Germany

Re: "CTRL + mousebutton 4" to send a key

10 Mar 2022, 14:34

Hi, GetKeyState only works for a single key, not a combination, so you probably have to check twice.
Maybe that's all :)

Edit: After testing, I can't get it to continually send g :think:

Edit2: What does work is this (though it continues after you release Ctrl but still hold XButton2):

Code: Select all

#SingleInstance Force

^XButton2::
	SetTimer, SendG, 100
	KeyWait, XButton2
	SetTimer, SendG, Off
return

SendG:
	Send, g
Return
Edit 3: Unless you actually want to hold the key for 100ms, what your script says, in that case you can do what you did, or call

Code: Select all

SetKeyDelay, 1, 100
Which then is active for all send, until you reset without parameters.
Last edited by Hardcoder on 10 Mar 2022, 14:53, edited 7 times in total.
RussF
Posts: 1311
Joined: 05 Aug 2021, 06:36

Re: "CTRL + mousebutton 4" to send a key

10 Mar 2022, 14:38

image.png
image.png (12.7 KiB) Viewed 541 times

Code: Select all

^XButton1::
    MsgBox, It works!
    Return
Russ
RussF
Posts: 1311
Joined: 05 Aug 2021, 06:36

Re: "CTRL + mousebutton 4" to send a key

10 Mar 2022, 14:51

Try:

Code: Select all

^XButton1::
    While GetKeyState("XButton1", "P" ) AND GetKeyState("Ctrl", "P" )
    {
        Send g
        Sleep 100
    }
    Return
Russ
Hardcoder
Posts: 278
Joined: 19 Feb 2022, 13:13
Location: Germany

Re: "CTRL + mousebutton 4" to send a key

10 Mar 2022, 15:00

RussF wrote:
10 Mar 2022, 14:51
Try:

Code: Select all

^XButton1::
    While GetKeyState("XButton1", "P" ) AND GetKeyState("Ctrl", "P" )
    {
        Send g
        Sleep 100
    }
    Return
Russ
Interesting, I did the same at first, but it didn't work at all, now it does most of the time.
I hope I don't need a new mouse :problem:

Edit: Nope, my mouse is ok, but as soon as I press the mouse button in addition to Ctrl, Ctrl state is toggling between pressed and released :think:
Edit2: So, the cause is the sending of g, I would guess because the script releases Ctrl very short, to not send ^g. I would prefer a different version then, that does not rely on Ctrl state, as that will obviously stop at random times (when Ctrl up and the check happen at the same time).
Last edited by Hardcoder on 10 Mar 2022, 15:15, edited 1 time in total.
RussF
Posts: 1311
Joined: 05 Aug 2021, 06:36

Re: "CTRL + mousebutton 4" to send a key

10 Mar 2022, 15:12

I'm sure it can be fine tuned. If I release xbutton1 while holding ctrl, the g's stop and start up again when I re-press xbutton1.

If I release ctrl while holding xbutton1, the g's stop, but DON'T start up when I re-press ctrl.

Hopefully @Silver can work within those constraints.

Russ
Hardcoder
Posts: 278
Joined: 19 Feb 2022, 13:13
Location: Germany

Re: "CTRL + mousebutton 4" to send a key

10 Mar 2022, 15:18

Yeah, maybe it doesn't even matter for him.
But anyway an interesting find for me :geek:
S1lver
Posts: 23
Joined: 07 Nov 2020, 04:14

Re: "CTRL + mousebutton 4" to send a key

20 Apr 2022, 06:25

Nice guys. Thx alot for trying to figure this out, and the same way confirm I'm not total noob😆
I will try it out, and see if I can make a workaround with what you wrote.
The point for the script is that xbutton1 is giving another command.
So that is why Ctrl has to be implemented.
Happy easter

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Lpanatt, peter_ahk and 293 guests