Page 1 of 1

EventHandler on multiple windows

Posted: Fri Feb 06, 2026 11:30 am
by amyren
Does eventhandler need to be installed seperately for each display or perhaps I install it wrongly here?

When running this code it only seem to detect events from the Display 2 window. Uncommenting those 3 lines near the bottom will make it take events from both windows.

Code: Select all

@DISPLAY {Title = "Display 1", X = #LEFT, Y = #TOP}

CreateDisplay(2, {Title = "Display 2", X = 100, Y = 100})
OpenDisplay(2)

Function p_HandlerFunc(msg)
	Switch(msg.Action)
	Case "OnMouseDown": 
		Switch(msg.id)
		Case 1:
			DebugPrint("Display 1 LMB")
		Case 2:
			DebugPrint("Display 2 LMB")
		EndSwitch
	Case "OnRightMouseDown":
		Switch(msg.id)
		Case 1:
			DebugPrint("Display 1 RMB")
			OpenDisplay(2)
		Case 2:
			DebugPrint("Display 2 RMB")
			CloseDisplay(2)
		EndSwitch
	Case "CloseWindow":
		Switch(msg.id)
		Case 1:
			Wait(50)
			CloseDisplay(1)
			End
		Case 2:
			CloseDisplay(2)
		EndSwitch
	EndSwitch
EndFunction

InstallEventHandler({OnMouseDown = p_HandlerFunc, OnRightMouseDown = p_HandlerFunc, CloseWindow = p_HandlerFunc})
;SelectDisplay(1)
;InstallEventHandler({OnMouseDown = p_HandlerFunc, OnRightMouseDown = p_HandlerFunc, CloseWindow = p_HandlerFunc})
;SelectDisplay(2)

Repeat
	WaitEvent()
Forever

Re: EventHandler on multiple windows

Posted: Sat Feb 07, 2026 1:46 pm
by airsoftsoftwair
Yes, you must install event handlers for display individually. This is a deliberate design choice to avoid unnecessary CPU load, e.g. the "OnMouseMove" event handler will generate lots of traffic and often you don't need it for all of your windows which is why you must install event handlers for each display separately.