Actually, the idea behind the new layer interactivity feature was to make programming easier, avoid creating and managing lots of event groups.
faaak2 You don't really need to know the total number of layers. You can run a loop Repeat 100 times, and disable interactivity for all layers - Set layer loopindex interactive=false.
Then enable interactivity only for the layer with the dialog.
Or make a simple function: