How to find listeners attached to an object

31 views (last 30 days)
Daniel
Daniel on 14 Aug 2014
Commented: DNF on 27 Apr 2021
Hi,
I thought this would be a trivial task, but I cannot find the way to do this. Given an object in your workspace, is there an easy way to get handles to all the listeners that have been defined on this object?
cheers, Daniel
  5 Comments
Adam Danz
Adam Danz on 15 Nov 2019
I wish there were a way to h=findall('listeners') or h=findall(obj,'listeners') or something like that because some listeners are created by functions that do not return object handles and I don't know of any other way to get the listener handles (although I've only searched briefly).
[addendum]
To add context to my previous comment that brought this 5+ year thread back to life, I am (was; partially gave up) trying to troubleshoot this problem:

Sign in to comment.

Answers (2)

Harry Dymond
Harry Dymond on 3 Jul 2020
Found the answer on StackOverflow: any object with listeners attached will have an undocumented property .AutoListeners__, which is a cell array of listener handles. The cell array does not appear to get "pruned" if listeners are deleted, so .AutoListeners__{x} could contain a handle to a deleted listener. If the object has never had listeners created for any of its properties, .AutoListeners__ will not exist.
  2 Comments
DNF
DNF on 27 Apr 2021
As far as I can tell this does not return all listeners. Listeners to some undocumented events do not show up. If you attach a listener to a window for its WindowMouseMotion event, then you cannot find that in the .AutoListeners__ array.

Sign in to comment.


Joakim Magnusson
Joakim Magnusson on 14 Aug 2014
Can't you save your listeners when created like this? :
handles.listener1 = addlistener(...);
handles.listener2 = addlistener(...);
etc...
Or that wont work for you?
  2 Comments
Joakim Magnusson
Joakim Magnusson on 14 Aug 2014
No i couldn't find anything like that either.

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by