houmain / keymapper

A cross-platform context-aware key remapper.
GNU General Public License v3.0
260 stars 22 forks source link

how to debug? #1

Closed mfinelli closed 3 years ago

mfinelli commented 3 years ago

Hi this project looks very interesting but I'm having trouble getting it to work and I'm not sure how to debug it. I've started by installing the package that you maintain on the AUR and then I've started keymapperd service which is running successfully.

Then as a proof-of-concept that this would suit my needs I tried writing the following config file to ~/.config/keymapper.conf

# abstract command mappings
Meta{C} >> copy
Meta{V} >> paste

# application-specific mappings
[Window system="Linux" title="Mozilla Firefox"]
  copy >> Control{C}
  paste >> Control{V}

Then I ran keymapper -u runs successfully. But when I try to use Cmd-C/V in firefox nothing happens. I'm not sure where to go next as neither keymapperd nor keymapper seem to have any kind of verbose output or really anything to let me know that it's working. Any help appreciated!

Cheers

houmain commented 3 years ago

Hi Mario, first of all thank you for trying it out and giving feedback and sorry for the late reply (now I should get notified).

Have you tried it with an even simpler configuration? e.g. A >> B If this does not work either - you only have one keyboard attached and are running X11? Testing with multiple keyboards is the next thing on my list, Wayland support will follow later. Yes, the output is a little bit scarce. I really should add a verbose mode.

I tested your configuration and found a problem I could fix, please reinstall from the AUR. There was a problem when Meta was hold too long before the C was pressed (keyrepeat). In this case Firefox received Meta-Control-C, which does nothing.

Cheers

mfinelli commented 3 years ago

Just to confirm A >> B should mean when I type A, I get B instead? I've tried this configuration but still not having any effect:

cat ~/.config/keymapper.conf
# abstract command mappings
# Meta{C} >> copy
# Meta{V} >> paste

# application-specific mappings
# [Window system="Linux" title="Mozilla Firefox"]
  # copy >> Control{C}
  # paste >> Control{V}
  # A >> B

A >> B

I was at first trying with a second keyboard (I usually have two plugged in) not realizing that wasn't supported but I also tried with just a single keyboard (and I restarted keymapperd) but still no luck. I am using X11.

I'm happy to provide any other info/logs/config/whatever if it's helpful.

Cheers

Azarattum commented 3 years ago

@mfinelli there is indeed a problem with multiple keyboard support on Linux. Even when I had a single keyboard it didn't work for me because the code grabs the first input device that looks like a keyboard. Turned out that my USB keyboard registered four different devices from which only one was real (others were sending some meta data like LED states, I have no clue why). I spend lots of hours trying to programmatically determine the real keyboard from all those devices, but it seemed like there is no simple solution, as these devices were almost identical.

The real solution was to implement support for multiple keyboards, which I did in my fork with assigning a thread for an each keyboard-like input device instead of grabbing only the first one: https://github.com/Azarattum/UniversalHotkeyer/commit/5c76586bae914ad204c1dfbab8f11af6e494f244

I also made an AUR package, if you want to try it out and see where it solves your problem: https://aur.archlinux.org/packages/hotkeyer-git/

houmain commented 3 years ago

@Azarattum yeah, some other device or a complex keyboard could have caused problems. I also implemented multi-keyboard support now (but without multiple threads). Hot-plugging multiple devices works quite well now.

Thank you @mfinelli. So it is likely, that it works now. I am still working on a verbose output mode...

Cheers

Azarattum commented 3 years ago

That sounds great! I'll take a closer look at it, as soon as I have some time.

Thank you for such a great project, btw.

mfinelli commented 3 years ago

@houmain with the latest (git) version installed my test case of Z >> Q is working with multiple keyboards. However, it starts working just after starting the keymapperd system service and before running the keymapper service as my local user but somehow still reading the ~/.config/keymapper.conf from my home directory. Is that an expected new behavior?

houmain commented 3 years ago

@mfinelli glad to hear that it works now! So you are wondering why it works without explicitly starting keymapper, right? The AUR package adds keymapper to the desktop environment's autostarted applications. If the keymapperd service is not running, keymapper does nothing but wait for the service to start.

Thanks for pointing this out, I will clarify it in the readme.

houmain commented 3 years ago

@Azarattum thank you for your appreciation!

mfinelli commented 3 years ago

Ah, I didn't catch that, makes perfect sense.

So, now if you're taking feature requests I have two :smile: (I'm also happy to open new issues if you prefer to close this one)

  1. An (optional) verbose mode so that I can see what the title of a window is when pressing keys so that I know what to put into the config file.
  2. Kind of related: it would be nice if you could make the title match (optionally) case-insensitive or a regex so that I could do something like:
[Window system="Linux" title="firefox"]
...

And it would match "Mozilla Firefox", but also "Firefox Developer Edition" for example.

Thanks for making such a cool project (and working with me to get it working!)

Also, FYI since I noticed that you tag releases I will probably start publishing the "stable" version of this in the AUR.

Cheers

houmain commented 3 years ago

The first feature request fits well in this issue and should be done now. I just pushed a version with optional verbose output. When you run keymapper with -v the detected window focus changes are output and when you run keymapperd with -v you can see the detected keyboard devices...

The window title comparison is currently case-sensitive but it already looks for sub strings. So [title="Firefox"] already matches "Mozilla Firefox" and "Firefox Developer Edition". I will open a new issue for regular expression support.

Thank you very much for maintaining the AUR package!

Cheers

mfinelli commented 3 years ago

Good to know that the substring match already works. I also just tried both keymapper and keymapperd with the verbose switch and it works perfectly and shows exactly what I would expect!