mouse long click on titleBar only / [key long hold] Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
monatilda23
Posts: 26
Joined: 25 Jan 2022, 10:24

mouse long click on titleBar only / [key long hold]

Post by monatilda23 » 29 Jan 2022, 01:28

hello AHK friends

what Im looking for is to run the script on the window title bar
actually I would like to long press RButton for Win+Ctrl+T combination.

the idea is that when I hold the RButton on title bar of the window, lets say for 3 secs, the script preform the job.

for this I found several scripts as parts for the whole script
_____

1) long pressing the key (here a guy wanted to replace letter with another on holding the key)

Code: Select all

$*c::
Send {Blind}{c}
KeyWait, c, T0.5
If ErrorLevel {
	Send {BackSpace}{ç}
	KeyWait, c
}
return
2)this is the script to press RButton on title bar, found on archived forums

Code: Select all

CoordMode, Mouse, Screen 
$RButton::
MouseGetPos, xPos, yPos, WindowUnderMouseID
WinGetClass, class, ahk_id %WindowUnderMouseID%
SendMessage, 0x84, , ( yPos << 16 )|xPos, , ahk_id %WindowUnderMouseID%
If (class <> "Shell_TrayWnd") and (ErrorLevel = 2)
		Msgbox, You right clicked in the title bar
Else
	Click Right
Return
_____


according to feedback those scripts work well, but for me I don't know how to combine it for the desired result
or maybe the solution might be even lighter on code amount


the Win+ctrl+T is a combination of MS Power Toys to make the window "On Top"
but I would like to pin window On Top by easier combination ( long RButton, because we very rare hold RButton for more than 1 sec)

please any help appreciated

amateur+
Posts: 655
Joined: 09 Oct 2021, 15:43

Re: mouse long click on titleBar only / [key long hold]  Topic is solved

Post by amateur+ » 29 Jan 2022, 03:41

Code: Select all

#if MouseIsOverTitleBar()
~RButton::
KeyWait, RButton, T1 ; or use T3 for three seconds.
if ErrorLevel {
	send, {Blind}{RButton Up}{Esc}#^t 
	KeyWait, RButton 
}
return
#if

MouseIsOverTitleBar() {
	CoordMode, Mouse, Screen 
	MouseGetPos, xPos, yPos, WindowUnderMouseID
	WinGetClass, class, ahk_id %WindowUnderMouseID%
	SendMessage, 0x84, , ( yPos << 16 )|xPos, , ahk_id %WindowUnderMouseID%
	return (class <> "Shell_TrayWnd") && (ErrorLevel = 2)
}
If you want, I can give you a script to pin/unpin AlwaysOnTop any window, not only your Toys.
Have found any drawback in my code or approach? Please, point it out. /The moderator ordered to remove the rest of the signature, I had obeyed.
And I really apologize for our russian president. Being a citizen of an aggressor country is very shameful. Personally I tried to avoid this trying to defend elections from fraud being a member of the election commission of one of the precincts but only was subjected to a hooligan attack and right before the vote count was illegally escorted from the polling station and spent the night behind bars (in jail) in a result of illegal actions of corrupt policemen.

monatilda23
Posts: 26
Joined: 25 Jan 2022, 10:24

Re: mouse long click on titleBar only / [key long hold]

Post by monatilda23 » 29 Jan 2022, 08:01

hello @amateur+ ! thank you so much for this script, you did it in great way, it seems to work very well ! at least it strictly does the job and leave no glitches, the only issue that I will be now thinking about is how to avoid right-click context menu poppin up when switching the on-top window "off". I mean, technically the process is the same for pinning and un-pinning, identically holding RButton, but the context menu appears only on second phase, when unpinning.
Anyway this is a cosmetic one compared to global success, maybe this is a Windows nature and nothing can be done.

The only reason why I want to do this via Microsoft Power Toys - not PinOnTop, DisplayFusion, XtraButtonz, Chameleon WM, and other software or even AHK script, is only because "Power Toys" app provides the user with a great visual solution to inform about "pinned" window and or recognize it among others. Personally I fell in love with this simple but practical and exclusive feature. Especially after testing tons of abovementioned software and apps which add ugly overlayed and mis-scaled "pins" on title bar and so on. Of course one might try to replace those icons via Resource Hacker, and I tried, but the result wasn't any better due to picture size restrictions.

Anyway, if you would share the proper on-top script I would spread this amount my friends or other people who would be interested just to pin the windows, not adding any visual additions.

Best regards

monatilda23
Posts: 26
Joined: 25 Jan 2022, 10:24

Re: mouse long click on titleBar only / [key long hold]

Post by monatilda23 » 29 Jan 2022, 10:02

hey @amateur+ I modified your script by erasing Tilda, as suggested here
and now the mentioned problem of context menu is gone
and the initial functions of your script still works ! so great thank you for the script very much

amateur+
Posts: 655
Joined: 09 Oct 2021, 15:43

Re: mouse long click on titleBar only / [key long hold]

Post by amateur+ » 29 Jan 2022, 16:29

I've installed those Toys to try and I can't reproduce the problem you're talking about, look under the spoiler below:
Spoiler
So you can add more delays between sent keys:

Code: Select all

#if MouseIsOverTitleBar()
~RButton::
KeyWait, RButton, T0.5 ; or use T3 for three seconds.
if ErrorLevel {
	SetKeyDelay, 30
	send, {Blind}{RButton Up}{Esc}#^t 
	KeyWait, RButton 
}
return
#if

MouseIsOverTitleBar() {
	CoordMode, Mouse, Screen 
	MouseGetPos, xPos, yPos, WindowUnderMouseID
	WinGetClass, class, ahk_id %WindowUnderMouseID%
	SendMessage, 0x84, , ( yPos << 16 )|xPos, , ahk_id %WindowUnderMouseID%
	return (class <> "Shell_TrayWnd") && (ErrorLevel = 2)
}
And you have to use tilda, otherwise you won't able to get a right-click-context menu over title bars when you don't want to hold for pinning.
Have found any drawback in my code or approach? Please, point it out. /The moderator ordered to remove the rest of the signature, I had obeyed.
And I really apologize for our russian president. Being a citizen of an aggressor country is very shameful. Personally I tried to avoid this trying to defend elections from fraud being a member of the election commission of one of the precincts but only was subjected to a hooligan attack and right before the vote count was illegally escorted from the polling station and spent the night behind bars (in jail) in a result of illegal actions of corrupt policemen.

Post Reply

Return to “Ask for Help (v1)”