I just found a behaviour of an EventHandler
that I cannot explain. Here is a highly simplified version. I will present two simple EventHandler
s. The first one shows the behaviour that I would have expected from the second one as well.
eventlist=Table[Invisible["10 pressed"], {10}];
eventnr=1;
aux[arg_String]:= (
eventlist=Take[Append[eventlist, ToString[eventnr]<>arg],-10];
eventnr=eventnr+1
);
Row[{
EventHandler[Framed[Style[x^2, 30]],{{"KeyDown","1"}:>aux[" pressed"]}],
Spacer[10],
Framed[Dynamic[Column[eventlist]]]
}]
When we click in the left box and then press the key 1 a number of times, we see in the right box how often we pressed the key. This works fine.
Now I place the Dynamic
expression in the EventHandler
:
eventlist = Table[Invisible["10 pressed"], {10}];
eventnr = 1;
aux[arg_String] := (
eventlist = Take[Append[eventlist, ToString[eventnr] <> arg], -10];
eventnr = eventnr + 1
);
EventHandler[
Framed[Dynamic[Column[eventlist]]]
, {{"KeyDown", "1"} :> aux[" pressed"]}
]
When I click in the box and press 1, it is recognized. But further pressing 1 has no effect, so it seems that the selection must have moved outside the box. When we click again in the box and press 1, it works, but only once. Can someone explain what is happening here?