Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Suggestion: Implement #IfMouseOverControl ClassNN like #IfWinActive


  • Please log in to reply
10 replies to this topic
TSRh
  • Members
  • 6 posts
  • Last active: Jul 16 2015 10:42 AM
  • Joined: 07 Jul 2015

It will be very helpful feature!

 

Thanks!



space
  • Members
  • 520 posts
  • Last active:
  • Joined: 12 Aug 2014
Just in case you don't know: you can already do that using #If - see the example (bottom of page) http://ahkscript.org...ommands/_If.htm

T_Lube
  • Members
  • 640 posts
  • Last active: Sep 09 2016 02:19 AM
  • Joined: 16 Oct 2014

I agree with space on this one. There would be no purpose since one could very easily make a function to use with the #if in an expression.



TSRh
  • Members
  • 6 posts
  • Last active: Jul 16 2015 10:42 AM
  • Joined: 07 Jul 2015

I found no way to remap mouse wheel only when cursor hovers control with ClassNN in some app window. Can you explain me, please, how can i make this ?



TSRh
  • Members
  • 6 posts
  • Last active: Jul 16 2015 10:42 AM
  • Joined: 07 Jul 2015

I tried this:

#IfWinActive ahk_class dopus.lister ; if Directory Opus Lister window is active
	SetTimer, CtrlChk, 50 ; runs the 'CtrlChk' subroutine once a second
return

CtrlChk:
    MouseGetPos, , , WhichWindow, WhichControl
    ControlGetPos, x, y, w, h, %WhichControl%, ahk_id %WhichWindow%
    if (WhichControl = "some_name")
	{
		ToolTip, %WhichControl%`nX%X%`tY%Y%`nW%W%`t%H%
		WheelDown::Send, {Control Down}{Left}{Control Up}
		WheelUp::Send, {Control Down}{Right}{Control Up}
	}

But to no avail (



Jackie Sztuk _Blackholyman
  • Spam Officer
  • 3757 posts
  • Last active: Apr 03 2016 08:47 PM
  • Joined: 28 Feb 2012

The #IfWinActive and other #if commends can not be used like that.

 

They affect hotkeys and hotstrings nothing else, so your timer will always run and normal if statements have no effect on hotkey or hotstring label definitions.

 

the help file shows this example

; Example 1: Adjust volume by scrolling the mouse wheel over the taskbar.
#If MouseIsOver("ahk_class dopus.lister")
WheelUp::Send {Volume_Up}
WheelDown::Send {Volume_Down}

MouseIsOver(WinTitle) {
MouseGetPos,,, Win
return WinExist(WinTitle . " ahk_id " . Win)
}

you can then modify that to try and check for a control


Helping%20you%20learn%20autohotkey.jpg?d

[AHK] Version. 1.1+ [CLOUD] DropBox ; Copy [WEBSITE] Blog ; About

TSRh
  • Members
  • 6 posts
  • Last active: Jul 16 2015 10:42 AM
  • Joined: 07 Jul 2015

 

The #IfWinActive and other #if commends can not be used like that.

 

They affect hotkeys and hotstrings nothing else, so your time will always run and normal if statements have no effect on hotkey or hotstring label definitions.

 

the help file shows this example

; Example 1: Adjust volume by scrolling the mouse wheel over the taskbar.
#If MouseIsOver("ahk_class dopus.lister")
WheelUp::Send {Volume_Up}
WheelDown::Send {Volume_Down}

MouseIsOver(WinTitle) {
MouseGetPos,,, Win
return WinExist(WinTitle . " ahk_id " . Win)
}
you can then modify that to try and check for a control

 

 

I have no idea how i should modify this ? This just doesn't work, i tried all options, even downloaded, installed and ran all code snippets under debugger. There is totally no way to remap when detected mouse over ClassNN in AutoHotKey framework! Everybody just saying that this is possible, but it's not (

So i think my suggestion will be very helpful.



Jackie Sztuk _Blackholyman
  • Spam Officer
  • 3757 posts
  • Last active: Apr 03 2016 08:47 PM
  • Joined: 28 Feb 2012

How about you try asking other users by making a topic in the "ask for help" sub forum about your issue? That's a great place to get support when you're unsure of how to modify scripts...


Helping%20you%20learn%20autohotkey.jpg?d

[AHK] Version. 1.1+ [CLOUD] DropBox ; Copy [WEBSITE] Blog ; About

TSRh
  • Members
  • 6 posts
  • Last active: Jul 16 2015 10:42 AM
  • Joined: 07 Jul 2015

At last, i just made it, and it even works somehow:

#If MouseIsOver("some_name")
~WheelUp::Send, {Control Down}{Left}{Control Up}
~WheelDown::Send, {Control Down}{Right}{Control Up}

MouseIsOver(WinTitle) {
MouseGetPos, , , WhichWindow, WhichControl
    ControlGetPos, x, y, w, h, %WhichControl%, ahk_id %WhichWindow%
    if (WhichControl = WinTitle)
	{
		return 1
		;WinExist(WinTitle . " ahk_id " . Win)
	}
	else
	{
		return 0
	}
}

Anyway, all this code would end up with just these lines, if my suggestion will be implemented ):

#IfMouseOverControl "some_name"
~WheelUp::Send, {Control}{Up}
~WheelDown::Send, {Control}{Down}

And by the way, this will not work if window is not active.

So it's a lot to do.

 

Thank you to all!

 

ps: sorry for my english



Lexikos
  • Administrators
  • 9844 posts
  • AutoHotkey Foundation
  • Last active:
  • Joined: 17 Oct 2006

Anyway, all this code would end up with just these lines, if my suggestion will be implemented

That is not a lot of code. Also, some of it is unnecessary. You get the position of the control, but never do anything with it. The IF, braces and separate return statements can be reduced to a single statement:
#If MouseIsOverControl("some_name")
~WheelUp::Send, ^{Left}
~WheelDown::Send, ^{Right}

MouseIsOverControl(QueryControl) {
    MouseGetPos, , , , MouseControl
    return (MouseControl = QueryControl)
}
You only need to write the function once, then you can use it with as many hotkeys as you want.
 

And by the way, this will not work if window is not active.
So it's a lot to do.

I'm not sure what you're trying to say, but I did observe that the keystrokes are sent to the focused control in the active window, not the control the mouse is pointing to, so it's not very sensible to have the hotkey work this way. This might fix it:
~WheelUp::
    WinActivate
    ControlFocus some_name
    Send, ^{Left}
    return
... or you could check the keyboard focus (WinActive/ControlGetFocus) instead of the mouse position. It seems unlikely that the user will want to move the caret (keyboard insertion point) by pointing the mouse at a control when the caret isn't even in that control.

There is a pre-made example for checking the focused control in the help file, under the one for checking the mouse window.

TSRh
  • Members
  • 6 posts
  • Last active: Jul 16 2015 10:42 AM
  • Joined: 07 Jul 2015

 

I'm not sure what you're trying to say, but I did observe that the keystrokes are sent to the focused control in the active window, not the control the mouse is pointing to, so it's not very sensible to have the hotkey work this way.

 

I'm trying to say, that this will not work if the visible window have no focus, i.e. not active. So, i'm getting ControlGetPos to compare with MouseGetPos and trying to remap in case when mouse hovers over control.

 

Thank you for comment!