Jump to content

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

Send mouse scrolls to window under mouse


  • Please log in to reply
142 replies to this topic
RobOtter
  • Members
  • 133 posts
  • Last active: Jul 24 2014 11:29 AM
  • Joined: 30 Jan 2005

What is the most flexible use for the middle mouse button (as we have found a very good one for the wheel now). I would like to make it dependent on the used application. KatMouse seems to have an option for "pushing windows into the background" if I understood it correctly from the description on its website.

I do not use the "push down" functionality since I don´t need it. But you can configure another button than wheel button (if your mouse has additional ones) to push down windows. KatMouse has only limited per-application settings: you can deactive support for single applications but can not define different actions of mouse buttons for different apps. I use my mouse driver for these purposes (MS IntelliPoint driver).

But it gets off-topic now... If you have further questions, please email me directly.

regards,
Rob

automaticman
  • Members
  • 658 posts
  • Last active: Nov 20 2012 06:10 PM
  • Joined: 27 Oct 2006

CoordMode, Mouse, Screen
return

WheelUp::
	MouseGetPos, m_x, m_y
	hw_m_target := DllCall( "WindowFromPoint", "int", m_x, "int", m_y )

	; WM_MOUSEWHEEL
	;	WHEEL_DELTA = 120
	SendMessage, 0x20A, 120 << 16, ( m_y << 16 )|m_x,, ahk_id %hw_m_target%
return

WheelDown::
	MouseGetPos, m_x, m_y
	hw_m_target := DllCall( "WindowFromPoint", "int", m_x, "int", m_y )

	; WM_MOUSEWHEEL
	;	WHEEL_DELTA = 120
	SendMessage, 0x20A, -120 << 16, ( m_y << 16 )|m_x,, ahk_id %hw_m_target%
return

To make use of my so beloved markup:
~ I compare this solution to digging for oil very deeply to get the powerful oil. (Powerful in terms of "oil can be converted into power" meaning it's just one form of power among many other forms like e.g. money, beautiness, intelligence, physical power, military power, mass, accelerated objects, changing anything changeable in any space...)

Where does it's power come from:
+ DllCall
+ SendMessage
+ << operations (one needs some amount of understanding of Knuth's books here)

The used principle might be formulated like: "Connect simple events like here mouse over with low-level events using e.g. DllCall, SendMessage and bitshift operations."

If anyone wants to find a topic to write a nice tutorial about, the three big plus signs above might be some hints.

Hammillian7
  • Members
  • 9 posts
  • Last active: Dec 31 2010 01:01 PM
  • Joined: 08 Jun 2008
I love mouse scrolling and use it a lot (now with Dexxa Mouse driver, which works for me with a Logitech wireless Mouse).

What I want is scrolling the control under the mouse, even if not active.

I tried this sample, derived from the documentation:

~RAlt & WheelDown::  ; Scroll right.
ControlGetFocus, fcontrol, A
MouseGetPos, , , id, control

Loop 1  ; <-- Increase this value to scroll faster.
{
    SendMessage, 0x114, 1, 0, %fcontrol%, A  ; 0x114 is WM_HSCROLL and the 1 after it is SB_LINELEFT.
    SendMessage, 0x114, 1, 0, %control%, A  ; 0x114 is WM_HSCROLL and the 1 after it is SB_LINELEFT.
}
return

It has 2 parts merged, because some applications are responsive to one kind and others to the other.

But it doesn't work in Excel, Access, etc.

Would it be easy to adapt your vertical examples (which I hadn't had time to try yet) to horizontal scrolling?

Thanks.

sashabe
  • Members
  • 24 posts
  • Last active: Aug 05 2013 11:34 AM
  • Joined: 09 Oct 2006

Here is a simple alternative. It actually works quite well. Well enough that I have finally removed KatMouse from my system.

note: should work with Windows 98+

CoordMode, Mouse, Screen
return

WheelUp::
	MouseGetPos, m_x, m_y
	hw_m_target := DllCall( "WindowFromPoint", "int", m_x, "int", m_y )

	; WM_MOUSEWHEEL
	;	WHEEL_DELTA = 120
	SendMessage, 0x20A, 120 << 16, ( m_y << 16 )|m_x,, ahk_id %hw_m_target%
return

WheelDown::
	MouseGetPos, m_x, m_y
	hw_m_target := DllCall( "WindowFromPoint", "int", m_x, "int", m_y )

	; WM_MOUSEWHEEL
	;	WHEEL_DELTA = 120
	SendMessage, 0x20A, -120 << 16, ( m_y << 16 )|m_x,, ahk_id %hw_m_target%
return


For me only this version work (scrolling breaks with others at all), but it scrolls only background window, no working scrolling with the foremost one. So I changed the shortcut to !Wheel, now i scroll foremost windows without Alt and background windows with it.

Smurth
  • Members
  • 120 posts
  • Last active: Feb 23 2014 09:58 PM
  • Joined: 13 Dec 2006
Another varaint; mostly cosmetic changes:
CoordMode, Mouse, Screen
SetWinDelay, -1
SetBatchLines,-1
SetKeyDelay, -1

; acceleration
_WHEELACC=0x280000
; max speed
_WHEELMAXN=0x1800000
; automatically activate window
_WHEELAUTOFOCUS=1

return


EasyWheel(d)
; if _WHEELAUTOFOCUS if set, check which window is under the mouse and gives it focus if it hasn't already
; then send scroll event to the control under the mouse
; original code from Shimanov: http://www.autohotkey.com/forum/viewtopic.php?t=6772#54821
{
Global _WHEELACC
	, _WHEELMAXN
	, _WHEELAUTOFOCUS
Static t, s


	if ( A_TickCount > 500+t) {
		t := A_TickCount
		s :=0x780000
	}
	else if (s < _WHEELMAXN)
		s += _WHEELACC

	MouseGetPos x, y, hwnd
	h := DllCall("WindowFromPoint", "int", x, "int", y)
	if _WHEELAUTOFOCUS && (hwnd<>WinExist("A"))
		WinActivate, ahk_id %hwnd%
	SendMessage, 0x20A, d*s,(y<<16)|x,, ahk_id %h%
}


WheelUp:: EasyWheel(1)
WheelDown:: EasyWheel(-1)


soggos
  • Members
  • 129 posts
  • Last active: Nov 30 2012 10:35 AM
  • Joined: 27 Mar 2008

Here is a simple alternative. It actually works quite well. Well enough that I have finally removed KatMouse from my system.

note: should work with Windows 98+

CoordMode, Mouse, Screen
return

WheelUp::
	MouseGetPos, m_x, m_y
	hw_m_target := DllCall( "WindowFromPoint", "int", m_x, "int", m_y )

	; WM_MOUSEWHEEL
	;	WHEEL_DELTA = 120
	SendMessage, 0x20A, 120 << 16, ( m_y << 16 )|m_x,, ahk_id %hw_m_target%
return

WheelDown::
	MouseGetPos, m_x, m_y
	hw_m_target := DllCall( "WindowFromPoint", "int", m_x, "int", m_y )

	; WM_MOUSEWHEEL
	;	WHEEL_DELTA = 120
	SendMessage, 0x20A, -120 << 16, ( m_y << 16 )|m_x,, ahk_id %hw_m_target%
return


For me only this version work (scrolling breaks with others at all), but it scrolls only background window, no working scrolling with the foremost one. So I changed the shortcut to !Wheel, now i scroll foremost windows without Alt and background windows with it.


Good and Great for me to, i like the scrolling without windows focused,
Simple and Effective, big thank's AHK-Forum

thx1200
  • Members
  • 1 posts
  • Last active: Aug 19 2009 04:29 PM
  • Joined: 19 Aug 2009
I found a program that doesn't like the very elegant solution by shimanov: Trillian Astra. Wheel scrolling doesn't work at all in Trillian's message windows while this script is active.

As a workaround, I look to see what the active app and hovered app are and send the default wheel messages if they are both trillian.exe. Unfortunately, that means no "hover scroll" for Trillian, but that's better than no wheel scrolling at all!

$WheelUp:: 
   MouseGetPos, m_x, m_y 
   hw_m_target := DllCall( "WindowFromPoint", "int", m_x, "int", m_y ) 
   WinGet,hoverproc,ProcessName,ahk_id %hw_m_target%
   WinGet,activeproc,ProcessName,A
   if (hoverproc = "trillian.exe" and activeproc = "trillian.exe")
   {
     Send,{WheelUp}
   }
   else 
   {
     SendMessage, 0x20A, 120 << 16, ( m_y << 16 )|m_x,, ahk_id %hw_m_target% 
   }
return 

$WheelDown:: 
   MouseGetPos, m_x, m_y 
   hw_m_target := DllCall( "WindowFromPoint", "int", m_x, "int", m_y ) 
   WinGet,hoverproc,ProcessName,ahk_id %hw_m_target%
   WinGet,activeproc,ProcessName,A
   if (hoverproc = "trillian.exe" and activeproc = "trillian.exe")
   {
     Send,{WheelDown}
   }
   else 
   {
     SendMessage, 0x20A, -120 << 16, ( m_y << 16 )|m_x,, ahk_id %hw_m_target% 
   }
return


iDrug
  • Members
  • 389 posts
  • Last active: Dec 22 2014 07:47 PM
  • Joined: 13 Oct 2009
Hi there!

I need your help. I know nothing about scripting/programming at all, so please, if it's not that hard for you: could you please adopt this script for my needs?

I use Firefox, Total Commander and Miranda (TabSRMM chat container + clist_modern). All these progs use tabs. Miranda and Firefox have it's own abilities to scroll tabs, and Total Commander hasn't.

I want to have a script that will be able to scroll anything under the cursor without activating it (and without scroll acceleration).

I've tried all of the scripts from this topic and each of them does only part of what I need, but this parts are different, so maybe it's possible to mix all the advantages of these scripts, throw away all disadvantages and then combine them into one single script.

Here are the exact details of what I need:
1. No activation of the scrollable objects.
2. Tab scroll for the 3 programs mentioned above.
3. No scroll acceleration.

In order to try to help you helping me:
The only script that partially (it has some bugs) supports scroll for miranda's container tabs is TheLeO's version of the script.

All other scripts brake the built-in ability of (at least) Miranda (or even Firefox's too). But even this script is not bug-free: when scrolling active window of chat log or tabs in the chat container (TabSRMM), it also scrolls contact list (bug works only for my lovely clist_modern, but not for clist_nicer, btw).

EDIT:
#SingleInstance force
; Run total commander.
Run, TOTALCMD.EXE

; Wait until it opens.
WinWait, ahk_class TTOTAL_CMD

; Setting timer to check if the process still alive.
SetTimer, CheckTC, On

WheelUp::
WheelDown::
  MouseGetPos, MouseX, MouseY, WinID, ControlNN, 1
  WinGetClass, WinClass, % "ahk_id " WinID

  ; Scrolling TotalCommander's tabs
  If (WinClass = "TTOTAL_CMD" && RegExMatch(ControlNN, "TMyTabControl[12]"))
  { PostMessage, 1075, % TC_Cmd := "400" (ControlNN = "TMyTabControl1" ? "1" : "2"), 0,, % "ahk_class " WinClass
    PostMessage, 1075, % TC_Cmd := "300" (A_ThisHotkey = "WheelDown" ? "5" : "6"), 0,, % "ahk_class " WinClass
  }

  ; Scrolling objects under cursor without activation.
  Else, PostMessage 0x20A, ((A_ThisHotKey="WheelUp")-.5)*A_EventInfo*(120<<17),(MouseY<<16)|MouseX, % ControlNN, % "ahk_id " WinID
Return

CheckTC:
  Process, Exist, TOTALCMD.EXE
  If !ErrorLevel
    ExitApp
Return
This script was written by Mad*Forces / ZeLen1y under WTFPL license and it works best for TotalCommander - it can scroll inactive part of window without activating it, can scroll tabs of (in)active part of window, can scroll foreground applications and explorer windows, also without activating them, but it works bad with firefox: if firefox is not active, and I try to scroll tabs or tab's content - nothing happens.
It works good with (in)active TabSRMM chat container, but not with it's tabs.
Please, ignore the timer, as this script was written specially for me and I really requested that thing.

iDrug
  • Members
  • 389 posts
  • Last active: Dec 22 2014 07:47 PM
  • Joined: 13 Oct 2009
please, don't ignore my post, I really need help badly! :(

fragman
  • Members
  • 1591 posts
  • Last active: Nov 12 2012 08:51 PM
  • Joined: 13 Oct 2009

I found a program that doesn't like the very elegant solution by shimanov: Trillian Astra. Wheel scrolling doesn't work at all in Trillian's message windows while this script is active.

As a workaround, I look to see what the active app and hovered app are and send the default wheel messages if they are both trillian.exe. Unfortunately, that means no "hover scroll" for Trillian, but that's better than no wheel scrolling at all!

$WheelUp:: 
   MouseGetPos, m_x, m_y 
   hw_m_target := DllCall( "WindowFromPoint", "int", m_x, "int", m_y ) 
   WinGet,hoverproc,ProcessName,ahk_id %hw_m_target%
   WinGet,activeproc,ProcessName,A
   if (hoverproc = "trillian.exe" and activeproc = "trillian.exe")
   {
     Send,{WheelUp}
   }
   else 
   {
     SendMessage, 0x20A, 120 << 16, ( m_y << 16 )|m_x,, ahk_id %hw_m_target% 
   }
return 

$WheelDown:: 
   MouseGetPos, m_x, m_y 
   hw_m_target := DllCall( "WindowFromPoint", "int", m_x, "int", m_y ) 
   WinGet,hoverproc,ProcessName,ahk_id %hw_m_target%
   WinGet,activeproc,ProcessName,A
   if (hoverproc = "trillian.exe" and activeproc = "trillian.exe")
   {
     Send,{WheelDown}
   }
   else 
   {
     SendMessage, 0x20A, -120 << 16, ( m_y << 16 )|m_x,, ahk_id %hw_m_target% 
   }
return


I think trillian needs the scroll event to be send to the textbox control in chat window. With a scroll script active, it scrolls only if I have the cursor over the textbox area. Unfortunately the ClassNN is the same for the chat log control above it, and if you use Tabs, the number at the end of classNN appears to be random. Comparing the positions and visibility of the controls might be a way to find the correct one.

I also noticed another program that has issues with it, AdiIRC (probably not so common, but I use it). It zooms the chat window when you scroll too fast...

jeffwalker
  • Members
  • 1 posts
  • Last active: Mar 01 2010 10:00 PM
  • Joined: 22 Feb 2010

Here is a simple alternative. It actually works quite well. Well enough that I have finally removed KatMouse from my system.

note: should work with Windows 98+

CoordMode, Mouse, Screen
return

WheelUp::
	MouseGetPos, m_x, m_y
	hw_m_target := DllCall( "WindowFromPoint", "int", m_x, "int", m_y )

	; WM_MOUSEWHEEL
	;	WHEEL_DELTA = 120
	SendMessage, 0x20A, 120 << 16, ( m_y << 16 )|m_x,, ahk_id %hw_m_target%
return

WheelDown::
	MouseGetPos, m_x, m_y
	hw_m_target := DllCall( "WindowFromPoint", "int", m_x, "int", m_y )

	; WM_MOUSEWHEEL
	;	WHEEL_DELTA = 120
	SendMessage, 0x20A, -120 << 16, ( m_y << 16 )|m_x,, ahk_id %hw_m_target%
return


For me only this version work (scrolling breaks with others at all), but it scrolls only background window, no working scrolling with the foremost one. So I changed the shortcut to !Wheel, now i scroll foremost windows without Alt and background windows with it.


Good and Great for me to, i like the scrolling without windows focused,
Simple and Effective, big thank's AHK-Forum


Thanks for this. I like it a lot. One thing, I used to have "~LControl & WheelUp" and down mapped to scroll to the left and right. It of course broke when I started using this script.

I tried replacing "0x20A" with "0x114" which is "WM_HSCROLL" which was used in my old hotkey, but that doesn't do anything. Am I missing something?

Thanks.

RUBn
  • Members
  • 36 posts
  • Last active: Nov 29 2013 10:02 PM
  • Joined: 21 May 2007
Thank you, shimanov!!
Solves soo many problems.

For those that integrated this in your big script, like me, you have to put the following line at the top of your script or you'll have some problems:
CoordMode, Mouse, Screen
(I don't think "return" below that is needed)

RUBn
  • Members
  • 36 posts
  • Last active: Nov 29 2013 10:02 PM
  • Joined: 21 May 2007

I found a program that doesn't like the very elegant solution by shimanov: Trillian Astra. Wheel scrolling doesn't work at all in Trillian's message windows while this script is active.

As a workaround, ....


I think trillian needs the scroll event to be send to the textbox control in chat window. With a scroll script active, it scrolls only if I have the cursor over the textbox area. ...

Confirmed! shimanov's solution doés work on Trillian Astra if you position you cursor over the chat input area (where you type your text), even if not active. (And otherwise it indeed doesn't. Unfortunate..)

RUBn
  • Members
  • 36 posts
  • Last active: Nov 29 2013 10:02 PM
  • Joined: 21 May 2007
I recently migrated to Autohotkey_L and shimanov's solution stopped working, I am afraid. Anyone know any solution?

rousni
  • Members
  • 133 posts
  • Last active: Today, 08:50 AM
  • Joined: 23 Mar 2006

I recently migrated to Autohotkey_L and shimanov's solution stopped working, I am afraid. Anyone know any solution?


Shimanov's solution stopped working for me too when I migrated from Autohotkey_L 32-bit to Autohotkey_L 64-bit version.