wavexx / screenkey

A screencast tool to display your keys inspired by Screenflick
https://www.thregr.org/~wavexx/software/screenkey/
GNU General Public License v3.0
757 stars 66 forks source link

Only display keys from a specific program or process? #44

Closed CD3 closed 7 years ago

CD3 commented 7 years ago

I don't understand how the X input system works, so perhaps my question does not make since, but here is my basic problem. I have a tool that reads scripts and runs them interactively (https://github.com/CD3/gsc), which is useful for giving demonstrations of command line utilities. It would be useful if these demos could show key presses for showing things like using the vim editor, or any other program that responds to key presses, so I added support for emitting key press events using the libxdo library.

screenkey will display the key presses that are sent by gsc, but I'd like to have it display only the key press events that gsc sends with the libxdo library and not they keys I press to tell gsc to load another line from the script. It is possible to filter they keys that are displayed by their source, or is it impossible to determine the source after the X server gets the event?

wavexx commented 7 years ago

On Tue, Apr 18 2017, C. D. Clark, III wrote:

screenkey will display the key presses that are sent by gsc, but I'd like to have it display only the key press events that gsc sends with the libxdo library and not they keys I press to tell gsc to load another line from the script. It is possible to filter they keys that are displayed by their source, or is it impossible to determine the source after the X server gets the event?

The event source is basically unknown.

If you're using xdotool with a window ID, you could filter the event by using the send_event flag.

You could filter the events by their window target (that is: show only events that go to specific windows). By what you're writing, you could exclude events that go to the terminal where you're writing.

Would that suffice?

CD3 commented 7 years ago

That's what I was afraid of. When my script runner is in keysym mode, it sends key presses to the current window. When I press a key to load the next line, it also gets sent to the same window. Maybe I can have the script runner send keys to a dummy window and then filter as you suggest. Does screenkey have an option to only display keys being sent to a specific window?

wavexx commented 7 years ago

On Tue, Apr 18 2017, C. D. Clark, III wrote:

the script runner send keys to a dummy window and then filter as you suggest. Does screenkey have an option to only display keys being sent to a specific window?

No, but it should be trivial enough to try and do some tests. In Screenkey/inputlistener.py, look at the _kbd_process function. Before the event is modified, you can check for ev.xkey.window and just return to skip unwanted events.

Adding some proper code would be a bit more work to do things properly.

CD3 commented 7 years ago

All right, I'll look into that. Thanks for the help.

Foxboron commented 7 years ago

I tried looking into this, but ev.xkey.window returns 0 regardless of the window used.

wavexx commented 7 years ago

Indeed, it looks like it's always 0 also on my system. I'm unsure if this is expected with XRecord, or if I made some mistake while decoding.

Foxboron commented 7 years ago

If you would like to look into getting the window ID, i'd gladly implement rest of the feature requested above.

wavexx commented 7 years ago

After a cursory look, I don't see any obvious mistake. I fear XRecord might tap into the event before the target window id is calculated. No obvious documentation about this. I'll have to look at where XRecord takes the event.

Foxboron commented 7 years ago

Implemented a POC using python-xlib to get the correct window id. https://github.com/Foxboron/screenkey/commit/98618e260b56cdf65891568ea5a60b50cf89e25a

wavexx commented 7 years ago

On Sun, Jul 09 2017, Morten Linderud wrote:

Implemented a POC using python-xlib to get the correct window id. Foxboron/screenkey@98618e2

I've seen people do that, but there's quite some overhead in this method, and it's sadly going to break if you use a complex input method with it's own composition window.

We're monitoring for focus changes. I wonder if that event contains the correct window ID. At the very least, we can use it to cache the current active ID.