Unable to apply autofire to XButton2 and XButton1 of mouse Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
A Keymaker
Posts: 455
Joined: 31 May 2022, 13:46
Location: Donjon du Château de Mérovingien

Unable to apply autofire to XButton2 and XButton1 of mouse

31 May 2022, 15:36

I tried out multiple auto-fire AHK scripts that I have found on the Internet. But it seems that the problem does not lay in scripts themselves but within a mouse or the particular software I am trying to affect

My goal is to use the commonly used for navigating in Windows Explorer and in web browsers additional "forward" and "backward" mouse buttons- in Media Player Classic x64 1.9.21.2 on Windows 10 Enterprise 20H2 19042.746. I want these buttons to fast forward and fast backward my video files. Right now in regards to rewinding my MPC has such settings:

Options > Player > Keys

Command: Jump Forward(medium)
Key: Shift + Right Arrow
ID: 902
Mouse Modifier: [EMPTY]
Mouse Windowed: X2 Down
Mouse FS Modifier: [EMPTY]
Mouse Fullsrceen: X2 Down
App Command: [EMPTY]
Remote Cmd: [EMPTY]
RepCnt: 5

Command: Jump Backward(medium)
Key: Shift + Left Arrow
ID: 901
Mouse Modifier: [EMPTY]
Mouse Windowed: X1 Down
Mouse FS Modifier: [EMPTY]
Mouse Fullsrceen: X1 Down
App Command: [EMPTY]
Remote Cmd: [EMPTY]
RepCnt: 5




I also have the

Options > Player > Keys > Global Media Keys

checkbox turned on


As for the

Options > Tweaks > Jump distance (small, medium, large in ms)

I have

3333
6666
9999


set as values

All of the above gives me the ability to jump back and forth 6.5 seconds- but unfortunately only one step at a time. I need to press an additional mouse button 3 times if I want to jump ~20 seconds, because holding down the button [or keys] pressed is not registered by Media Player Classic as repeated pressing



And now the problem:

If using an AHK file I make an auto-fire for e.g. Left Mouse Button or a letter X, I am able to successfully apply auto-fire feature to them. Thus I can enrich my MPC with fast forward / backward functionality. But if in such A-OK working scripts I replace

Code: Select all

LButton
or

Code: Select all

X
with

Code: Select all

XButton2
or

Code: Select all

XButton1
then those additional buttons in MPC stop working entirely


So the question is: is this the fault of Media Player Classic, of AutoHotkey 1.1.34.02 or the software of my mouse?

The device in question is Logitech Mouse MX Anywhere 2, with firmware 013.010.00003 and Logitech Options 8.54.161 installed [which provides very basic options, through which I went through looking for any hints of erroneous / buggy settings]


And yes- the workaround to this would be based on a simple

Code: Select all

XButton2::
Send {RShift down}{Right down}
KeyWait, space
Send {RShift up}{Right up}
return
button to keys assignment- but that is not the point of my inquiry

My issue is with the issue of XButton2 & XButton1 vs. autofire. What is the problem with that?
Last edited by A Keymaker on 02 Jun 2022, 14:46, edited 1 time in total.
User avatar
Scr1pter
Posts: 1277
Joined: 06 Aug 2017, 08:21
Location: Germany

Re: Unable to apply autofire to XButton2 and XButton1 of mouse

31 May 2022, 16:34

Hello,

One thread would have been enough, but ok.

What does happen right now when you press these 2 buttons without ANY ahk script in background?
Do they actually forward and backward pages in web browser?

You can right-click on an running AHK script, click open, go to View and check "Key history".
Then you can press keys, buttons and refresh with F5 key.
It should show you exactly the names of these 2 mouse buttons.

Normally they should be xbutton1 and xbutton2, so I don't understand why it does not work for you.
ahkKeyhistory.png
ahkKeyhistory.png (16.47 KiB) Viewed 2009 times
Cheers!
Please use [code][/code] when posting code!
Keyboard: Logitech G PRO - Mouse: Logitech G502 LS - OS: Windows 10 Pro 64 Bit - AHK version: 1.1.33.09
User avatar
A Keymaker
Posts: 455
Joined: 31 May 2022, 13:46
Location: Donjon du Château de Mérovingien

Re: Unable to apply autofire to XButton2 and XButton1 of mouse

02 Jun 2022, 16:46

All of my extra mouse buttons always have been working A-OK. And the Back and Forward I was even able just recently to bind in Winamp to Left and Right arrows, thus to use my mouse to jump withing audio files back and forth

I did check their names- they are described as XButton1 and XButton2

And I just tried one auto-fire script that I found at https://stackoverflow.com/questions/71422481/how-to-fire-a-hotkey-when-a-key-is-pressed-rather-than-when-it-is-released-witho


And so after adjusting it to

Code: Select all

~XButton2::
    Send {RShift down}{Right down}
    Sleep, 111
    while GetKeyState("XButton2")
    {
        Send {RShift down}{Right down}
        Sleep, 111
    }
    Send {RShift up}{Right up}
return
I theoretically have now what I wanted

But I say theoretically because it works in an inconsistent way: sometimes after quick release it [apparently] registers just one click and jumps according number of seconds but immediately goes back, sometimes it jumps according number of seconds [i.e. 6.5 seconds] after quick release, sometimes [also despite quick releasing of the button] it registers 2-4 clicks thus jumps ~x3 the distance [e.g. 20 instead of 6.5 seconds]. And I know that this is govern by the Sleep parameter, but overall it just works in a wacky way. I tried adjusting both of these Sleep values but ended up either with a buggy-like behavior or consistent behavior but way too slow to be called fast-forwarding [which is what I am after]

So my question now is: is there a way to implement into such script a task of: after pressing XButton2 "press" simultaneously Right Shift and Right Arrow, then wait [lets say] 555 milliseconds - and if the XButton2 is still being hold down execute the above code?

So in other words, what I need is the code pasted in above by me to execute itself "once" and after a short pause continue until the button is physically released
User avatar
A Keymaker
Posts: 455
Joined: 31 May 2022, 13:46
Location: Donjon du Château de Mérovingien

Re: Unable to apply autofire to XButton2 and XButton1 of mouse

16 Jun 2022, 12:05

Keymaker wrote:
02 Jun 2022, 16:46
[...]
And so after adjusting it to
[...]
works in an inconsistent way
[...]
ended up either with a buggy-like behavior or [...] too slow to be called fast-forwarding
[...]
So my question now is

[...]
to execute itself "once" and after a short pause continue until the button is physically released
I found this viewtopic.php?f=7&t=41683 and tried using the

Code: Select all

SendMessage, 0x111, 902,,, ahk_class MediaPlayerClassicW
But it only helped a little [if anything]. And I think there might be something profoundly wrong with Media Player Classic itself and / or it receives different keys in a different ways [to which previously attest my initial finding of auto-fire scripts working A-OK for LButton]



Because now when I tried lowering values of distances for Jump Medium and Jump Long- and instead of having them smaller I was experiencing them fixed to apparently 10 seconds or multiplications of that 10 seconds whenever I pressed forward / backward mouse buttons. Long story short I shortened my Jump Small from 3333 milliseconds to 2500 [as it was the only field reacting in a proper way] and as I already had in MPC under the

Options > Player > Keys

a binding of Jump Backward (Small) to Middle Mouse Button and CTRL + Left Arrow and also a binding of Jump Forward (Small) to CTRL + Right Arrow - I have tested a variant of AHK code with Ctrl instead of Shift:

Code: Select all


~XButton2::   ; Browser Back Mouse Button
	Send {Ctrl Down}{Right Down}
	while GetKeyState("XButton2")
	{
		Send {Ctrl Down}{Right Down}
	}
	Send {Ctrl Up}{Right Up}
return

~XButton1::   ; Browser Forward Mouse Button
	Send {Ctrl Down}{Left Down}
	while GetKeyState("XButton1")
	{
		Send {Left Down}   ; NOTE THE LACK OF >>{Ctrl Down}<< WHICH IS PRESENT IN THE FORWARD VERSION
	}
	Send {Ctrl up}{Left Up}
return

And it seems to have worked - i.e.:

A] a quick pressing of backward / forward mouse button makes the video jump 10-15 second

B] a quick pressing of backward mouse almost never results with a glitch of jumping backward 1-3 seconds [as indicated by the time bar] and then immediately jumping forward thus going back with playback to the point before button pressing

C] pressing of middle mouse button jumps less than 3 seconds back

And thus with using only mouse I can either go back just a moment rewind of forward greater lengths without having to clicking multiple times. And if for whatever reason will not have the script running, then my forward / backward mouse buttons will still work, but in a different way

Unfortunately despite using Sleep in various lines of this code I was still unable to force it to wait for receiving [physical] prolonged hold down state of mouse button - thus I am unable to rewind just 2.5-6 seconds when I press those buttons and right away release then


So once again:
is there a way to implement into such script a fail-safe in form of executing single Send, then waiting a little - and only if button is still pressed Send repeated commands
?
User avatar
A Keymaker
Posts: 455
Joined: 31 May 2022, 13:46
Location: Donjon du Château de Mérovingien

Re: Unable to apply autofire to XButton2 and XButton1 of mouse  Topic is solved

12 Jul 2022, 13:36

Keymaker wrote:
16 Jun 2022, 12:05
[...]
So once again:
is there a way to implement into such script a fail-safe in form of executing single Send, then waiting a little - and only if button is still pressed Send repeated commands
?
It seems that those 2 [4] Sleep additions seem to do the trick

Code: Select all

#If WinActive("ahk_exe C:\Program Files (x86)\K-Lite Codec Pack\MPC-HC64\mpc-hc64.exe")

~XButton2::   ; Browser Forward Mouse Button = Fast Forward
    Send {Space Down}   ; This pauses the playback- which averts the unpleasing audio issue of truncated sound glitches
    Send {Ctrl Down}{Right Down}
    Sleep, 333
    while GetKeyState("XButton2")
    {
        Send {Ctrl Down}{Right Down}
    }
    Send {Ctrl Up}{Right Up}
    Send {Space}   ; This restores the playback
    Sleep, 111
return

~XButton1::   ; Browser Backward Mouse Button = Fast Backwards
    Send {Space Down}   ; This pauses the playback- which averts the unpleasing audio issue of truncated sound glitches
    Send {Ctrl Down}{Left Down}
    Sleep, 333
    while GetKeyState("XButton1")
    {
        Send {Left Down}{Ctrl Down}
    }
    Send {Ctrl up}{Left Up}
    Send {Space}   ; This restores the playback
    Sleep, 111
return

I also upgraded the code with a feature of pausing of playback - which helps with a sound issue
Last edited by A Keymaker on 16 Jul 2022, 10:22, edited 4 times in total.
User avatar
A Keymaker
Posts: 455
Joined: 31 May 2022, 13:46
Location: Donjon du Château de Mérovingien

Re: Unable to apply autofire to XButton2 and XButton1 of mouse

12 Jul 2022, 13:49

This however
Keymaker wrote:
16 Jun 2022, 12:05
[...]
now when I tried lowering values of distances for Jump Medium and Jump Long- and instead of having them smaller I was experiencing them fixed to apparently 10 seconds or multiplications of that 10 seconds whenever I pressed forward / backward mouse buttons
[...]
is still an issue


In other words: when the AHK file with the above script is active, then my setting for Jump Long in Media Player Classic [utilized by this script] is ignored - and instead of them ~10 seconds are used. But the moment I close it, a value chosen by me within MPC under the

Options > Tweaks > Jump distance (small, medium, large in ms) > [THE LAST THIRD BOX]

is obeyed by that player



So if anyone knows why this happens and / or how to avoid this [i.e. make Media Player Classic utilize Jump Long value when the above script is running] then please post it here anytime

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: CoffeeChaton and 149 guests