I want to be able to pass a Fakekeypress to a window already in focus without switching to it, or doing anything fancy. I just want a function to pass a Fakekeypress to a window that already has focus, ala:
AddToFunc FuncFoo
+ I WindowId $[w.id] Fakekeypress press F1 release F1
My understanding is that the above will pass the Fakekeypress to the Window that currently is in focus - because it is the window that is currently being ‘pointed to’ for lack of a better expression by $[w.id] - is that not true?
if I have to do something else before I can pass this keypress (or anything) to the application that currently has focus, please, somebody let me know.
That’s right. In this context $[w.id] will expand to the operand window – which in this case, is the only that has the focus. You could always just use:
+ I FakeKeyPress ......
Or in those instances where you know the window might not have focus:
+ I ThisWindow ......
That looks OK to me. Is there any reason it has to be a fakekeypress? You can in 2.5.X bind certain keys to specific windows, and propogate the event down to the window, where necessary.
the problem that I have is as follows:
When I try to send a FakeKeypress to a window that is already in focus - the synthetic event is never reaching the target window, unless I press the CTRL or SHIFT key a few seconds later.
My code reads as below:
Key F23 A N FuncFocusFoo
DestroyFunc FuncFocusFoo
AddToFunc FuncFocusFoo
+ I FuncProxyApps "Foo"
DestroyFunc FuncProxyApps
AddToFunc FuncProxyApps
+ I Next ($$0, !Focused, !Sticky, CirculateHit) SwitchToFoo
+ I TestRc (Match) Break
+ I Next ($$0, Focused, !Sticky, CirculateHit) PassKeyToFoo
#Helper function
DestroyFunc SwitchToFoo
AddToFunc SwitchToFoo
+ I Iconify off
+ I Raise
+ I Focus
+ I WarpToWindow
#Helper function
DestroyFunc PassKeyToFoo
AddToFunc PassKeyToFoo
+ I ThisWindow FakeKeypress press F23 release F23
Foo is easily warped to if it is not in focus, but when I try to pass the synthetic keypress to Foo via the “PassKeyToFoo” function (when it is in focus), the keypress just doesn’t get there (unless I hit SHIFT, or CTRL a few seconds later) – So, do XEvents - real or synthetic - sit in a buffer, or queue - and then pass from there to their target window? And if that window isn’t accessible, does it just sit in the buffer until something else comes in, and then it piggy-backs those next events on to the ‘new’ target window? If that is the case, is it possible to FORCE that keypress out of the buffer/queue without pressing anoth key?
I am frustrated in trying to get this key to propogate onto a window that is already in FOCUS! sigh
NOTE: I have a handleKeyPress X widget in this Foo application that I have piping out to a log file when keypresses arrive, and with the above code, it is never arriving, unless I hit another key after the REAL F23 keypress. Not understanding anything about X, I am lost as to why this event (synthetic in this case) is getting ‘stuck’ somewhere - anyone out there have any ideas?
Does this pressing CTRL or what have you only happen to this one application? Does it happen if you have your listener running? Indeed, have you tried adding a FakeKeypress for control to your command, to see if that has any effect?