I am working on some modifications to EEGlab's eegplot
function (things like vim-style navigation etc.) that need to work through WindowKeyPressFcn
.
However, the callback is not being called for some reason. I have been debugging the issue for some time and am a bit lost. I am looking for suggestions on what might be wrong. Unfortunatelly the eegplot
function is big, complex and somewhat convoluted and I was unable to reproduce the issue in a simple example. Therefore I am looking for general suggestions on why a function handle that is clearly present in WindowKeyPressFcn
might stop being used at some point.
Here is what I have learned so far:
eegplot
(set a breakpoint near the end of the setup function [the first half of eegplot]) I am able to run the WindowKeyPressFcn
at least once. eegplot
without debug (that is wait for it to finish and return control to me) I am unable to call WindowKeyPressFcn
by pressing a key. The function handle is still present in WindowKeyPressFcn
property of the figure.Whener the WindowKeyPressFcn
is not being used when I press a key, I can still call it with:
figh = gcf;
fun = get(figh, 'WindowKeyPressFcn');
ev.Key = 'rightarrow';
ev.Character = ' ';
ev.Modifier = [];
feval(fun, figh, ev);
So the function handle is 'healthy' so to speak, but for some reason it is not being used any more when a key is pressed and the figure has focus. When and why something like this could happen? Any ideas on things I should check to understand this issue?
Update:
I found out that WindowKeyPressFcn callback can sometimes be blocked by some window listeners, and tried out the following solution:
hManager = uigetmodemanager(gcf);
set(hManager.WindowListenerHandles,'Enable','off');
It doesn't work - WindowKeyPressFcn is still not called when I press a key. :(
Update 2:
Another thing that does not work:
chld = get(gcf, 'Children');
tp = get(chld, 'type');
chld = chld(strcmp(tp, 'uicontrol'));
set(chld, 'KeyPressFcn', @eegplot_readkey_new)
(eegplot_readkey_new
is the function I use for reacting to keypresses)
Update 3:
And another one not working:
addlistener(gcf, 'WindowKeyPress', @eegplot_readkey_new);
Ok - I fiugred it out, although the solution is weird to say the least.
For some mysterious reason using linesmoothing
undocummented property prevents WindowKeyPressFcn
from being called. I have absolutely no idea why...