EventHandler on multiple windows

Find quick help here to get you started with Hollywood
Post Reply
amyren
Posts: 441
Joined: Thu May 02, 2019 11:53 am

EventHandler on multiple windows

Post 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
User avatar
airsoftsoftwair
Posts: 5914
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

Re: EventHandler on multiple windows

Post 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.
Post Reply