Hold down Xbutton 1 while move scroll wheel up to send !PgDn Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
samt
Posts: 62
Joined: 09 Sep 2022, 13:29

Hold down Xbutton 1 while move scroll wheel up to send !PgDn

Post by samt » 03 Dec 2023, 01:49

Not sure how to go about doing this. Xbutton 1 is my back button, but when I make it part of a hotkey where I press it with another keyboard button, the "back" feature of the button goes away .
So maybe making it only work as an ahk hotkey if it's pressed and held down for more than 0.4s, and user moves mouse wheel up will initiate sending !{PgUp}. If Xbutton1 is just pressed quickly like a normal button, it would still function as my normal "back" button.

Tried things along the lines of...

Code: Select all

Xbutton1::
Loop
{
    keywait, Xbutton1, T0.4
    if (Errorlevel = 1)
    {
        GetKeyState, state, Xbutton1
        if (state = "D") ; so if Xbutton1 is held down...
        {
         if (WheelUp)  ;      ....AND mouse wheel up occurs by user...
            send, !{PgDn} ;... then send this
        }
        else
            break
    }

}

[Mod edit: Added [code][/code] tags. Please use them yourself when posting code.]

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

Re: Hold down Xbutton 1 while move scroll wheel up to send !PgDn

Post by boiler » 03 Dec 2023, 03:10

samt wrote: Not sure how to go about doing this. Xbutton 1 is my back button, but when I make it part of a hotkey where I press it with another keyboard button, the "back" feature of the button goes away .
That shouldn’t happen if you use one of the standard modifier keys and specify your hotkey(s) like this (not use & to create a customer combination):

Code: Select all

+XButton1::MsgBox, Shift+XButton1 was pressed
^XButton1::MsgBox, Ctrl+XButton1 was pressed

samt
Posts: 62
Joined: 09 Sep 2022, 13:29

Re: Hold down Xbutton 1 while move scroll wheel up to send !PgDn

Post by samt » 03 Dec 2023, 18:53

boiler wrote:
03 Dec 2023, 03:10
samt wrote: Not sure how to go about doing this. Xbutton 1 is my back button, but when I make it part of a hotkey where I press it with another keyboard button, the "back" feature of the button goes away .
That shouldn’t happen if you use one of the standard modifier keys and specify your hotkey(s) like this (not use & to create a customer combination):

Code: Select all

+XButton1::MsgBox, Shift+XButton1 was pressed
^XButton1::MsgBox, Ctrl+XButton1 was pressed
I described that part incorrectly actually. I want to press and hold Xbutton1, and then after like 0.4, move the wheel up to automatically send !{PgDn}, while still being able to simply press Xbutton1 for "back". Xbutton1 is a button on my gaming mouse so the whole command is done with just 1 hand on my mouse.

samt
Posts: 62
Joined: 09 Sep 2022, 13:29

Re: Hold down Xbutton 1 while move scroll wheel up to send !PgDn

Post by samt » 03 Dec 2023, 18:59

Seems like I need a nested 'if' statement but I haven't been able to get it to work

samt
Posts: 62
Joined: 09 Sep 2022, 13:29

Re: Hold down Xbutton 1 while move scroll wheel up to send !PgDn

Post by samt » 03 Dec 2023, 19:03

actually I think I might have it...gonna post in a bit. Doesn't need nested 'if' I think

samt
Posts: 62
Joined: 09 Sep 2022, 13:29

Re: Hold down Xbutton 1 while move scroll wheel up to send !PgDn

Post by samt » 03 Dec 2023, 19:42

Not quite right.. "back" functionality doesnt work if I just press Xbutton1. I want to be able to send a !{PgUp} command each time mouse wheel up occurs, all while holding down Xbutton1. Currently only lets me send 1 command of !{PgUp} each time I press and hold Xbutton1 and move mouse wheel up.

Code: Select all

Xbutton1:: 
KeyWait, WheelUp, T0.50       
    If ErrorLevel 
	{     
       send, !{PgUp}  
        } 
	Else  
       send, Xbutton1
return

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

Re: Hold down Xbutton 1 while move scroll wheel up to send !PgDn  Topic is solved

Post by boiler » 03 Dec 2023, 21:31

Untested, but it seems like it should be more like this:

Code: Select all

XButton1:: 
	KeyWait, XButton1, T0.50
	if !ErrorLevel
	     Send, XButton1
return

#If GetKeyState("XButton1", "P")
WheelUp::Send, !{PgUp}

samt
Posts: 62
Joined: 09 Sep 2022, 13:29

Re: Hold down Xbutton 1 while move scroll wheel up to send !PgDn

Post by samt » 05 Dec 2023, 17:06

boiler wrote:
03 Dec 2023, 21:31
Untested, but it seems like it should be more like this:

Code: Select all

XButton1:: 
	KeyWait, XButton1, T0.50
	if !ErrorLevel
	     Send, XButton1
return

#If GetKeyState("XButton1", "P")
WheelUp::Send, !{PgUp}
Close to perfect, but my Xbutton1 still loses its functionality as my "back" function if I just press the button. I've tried lots of different code now but can never get the "back" functionality of the button to remain while being able to hold it and move scroll wheel up to send !{PgUp}. It's for F.lux to change monitor brightness. I've given up on trying. Just cant get it perfect. Thanks for the help though.

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

Re: Hold down Xbutton 1 while move scroll wheel up to send !PgDn

Post by boiler » 05 Dec 2023, 22:01

samt wrote: Close to perfect, but my Xbutton1 still loses its functionality as my "back" function if I just press the button. I've tried lots of different code now but can never get the "back" functionality of the button to remain while being able to hold it and move scroll wheel up to send !{PgUp}.
Oops. I forgot to change what was wrong with the Send command:

Code: Select all

 	     Send, {XButton1}

samt
Posts: 62
Joined: 09 Sep 2022, 13:29

Re: Hold down Xbutton 1 while move scroll wheel up to send !PgDn

Post by samt » 06 Dec 2023, 20:34

boiler wrote:
05 Dec 2023, 22:01
samt wrote: Close to perfect, but my Xbutton1 still loses its functionality as my "back" function if I just press the button. I've tried lots of different code now but can never get the "back" functionality of the button to remain while being able to hold it and move scroll wheel up to send !{PgUp}.
Oops. I forgot to change what was wrong with the Send command:

Code: Select all

 	     Send, {XButton1}
Amazing...thank you so much!! It works flawlessly now. I'm a bit surprised that I myself didn't notice the { } missing.

Code: Select all

XButton1:: 

	KeyWait, XButton1, T0.20
	if (!ErrorLevel)
	     {
	       Send, {XButton1}
	     }
	return
		 
#If GetKeyState("XButton1", "P")
	WheelUp::Send, !{PgUp}
	WheelDown::Send, !{PgDn}
#If

Post Reply

Return to “Ask for Help (v1)”