Activate window after click in other monitor

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
dtsmarin2
Posts: 11
Joined: 18 Jun 2018, 19:30

Activate window after click in other monitor

18 Jun 2018, 19:44

Hi,

I'm using a touchscreen as my 3rd monitor but each time I touch something on it the window on my main monitor will lose focus so I have to Alt+Tab.
Is there any way to detect click (not swap/scroll) on the 3rd monitor and then switch back to the window on the main screen?

PS: Total noob, need to work so I can't invest time into learning AHK at the moment.

Thanks
User avatar
DyaTactic
Posts: 221
Joined: 04 Apr 2017, 05:52

Re: Activate window after click in other monitor

19 Jun 2018, 16:12

Try if this works. It's a bit complicated to leave all the normal functions of the mouse intact but this seems to work quite well:

Code: Select all

SysGet, MonCount, MonitorCount
SysGet, 3rdMon, Monitor, 3	; Assuming you touchscreen is monitor 3.
; The abonve command writes 3rdMonLeft, 3rdMonTop, 3rdMonRight and 3rdMonBottom 
; with the bounding coordinates of the 3rd monitor.

#If MonCount>2
$LButton::
	CoordMode, Mouse, Screen
	MouseGetPos, Mx, My	; Get the new position of the mouse.
	
	; Check if the click was on the 3rd monitor.
	If (Mx >= 3rdMonLeft) AND (Mx <= 3rdMonRight) AND (My >= 3rdMonTop) AND (My <= 3rdMonBottom)
	{
		; The mouse press was on the 3rd monitor, wether it was a mouse or a touchscreen click.
		
		OldWinHandle := WinExist("A")	; Save the old window to activate is later.
		
		SEND, {Blind}{Click Down}
		KeyWait, LButton
		WinActivate, ahk_id %OldWinHandle%
	} Else {
		SEND, {Blind}{Click Down}
		;MsgBox, PriMon=%PriMon%`nMonCount=%MonCount%`n`3rdMonLeft=%3rdMonLeft%`n3rdMonTop=%3rdMonTop%`n3rdMonRight=%3rdMonRight%`n3rdMonBottom=%3rdMonBottom%
	}
Return
~LButton Up::
#If
Note that the mouse is not moving back to the original window. It might be possible via OnMessage() but that's to much for today.

Let me know how this works.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Chunjee, mikeyww and 284 guests