Jump to content

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

How to activate the window currently under mouse cursor?


  • Please log in to reply
2 replies to this topic
orbik
  • Members
  • 36 posts
  • Last active: Jul 11 2015 05:35 PM
  • Joined: 09 Apr 2008
I want to make a mouse button trigger different hotkeys based on where it's clicked. Naturally I first thought the #IfWin directives should do it, but they only check which window has the keyboard focus, not where the mouse cursor actually is when clicking.

For my purposes it would be enough to first activate whatever window is under the cursor, then use IfWinActive blocks to choose the appropriate function. But how do I find what that window is without interacting with it directly?

Thanks for any helpful comments

Learning one
  • Members
  • 1483 posts
  • Last active: Jan 02 2016 02:30 PM
  • Joined: 04 Apr 2009
Activates the window currently under mouse cursor...
#Persistent
SetTimer, ActivateWinUM, 100
return

ActivateWinUM:
MouseGetPos,,, WinUMID
WinActivate, ahk_id %WinUMID%
return


orbik
  • Members
  • 36 posts
  • Last active: Jul 11 2015 05:35 PM
  • Joined: 09 Apr 2008
Oh, right. GetMousePos does exactly what I asked, thank you.

...but what's the point with that timer? :p Here's how I did it:

EDIT:
MButton:: 
MouseGetPos,,, hwnd 
WinActivate, ahk_id %hwnd%

IfWinNotActive ahk_class OperaWindowClass
	Click 2 
Else
	Click, Middle
	
return