zsugabubus / interception-k2k

Configurable plugin for Interception Tools (caps2esc, space2meta, tab2altgr...)
GNU General Public License v3.0
52 stars 10 forks source link

KEY_SPACE and HJKL into ARROWS #4

Open maricn opened 3 years ago

maricn commented 3 years ago

My setup

Thank you for writing and sharing this piece of code. I tried to read into it, and find it a bit confusing, so I'm asking for your kind help. :)

I'm on Arch on Wayland with SwayWM. I'm using latest AUR for interception-tools and evtest.

/etc/interception/udevmon.d/keymod.yaml:

- JOB: "intercept -g $DEVNODE | /opt/interception/maricn | uinput -d $DEVNODE"
  DEVICE:
    EVENTS:
      EV_KEY: [KEY_CAPSLOCK, KEY_ESC, KEY_SPACE]

/etc/udevmon.yaml:

# - JOB: "intercept -g $DEVNODE | uinput -d $DEVNODE"
#   DEVICE:
#     NAME: "AT Translated Set 2 keyboard"

Problem 1 - can't run make test

Hi, I would like to run tests, but make always throws errors...

nikola@work-x1c-arch ~/T/interception-k2k (master *+)» sudo env CONFIG_DIR=/home/nikola/Tools/interception-k2k/maricn make test
[sudo] password for nikola:
CFLAGS=-DVERBOSE make
make[1]: Entering directory '/home/nikola/Tools/interception-k2k'
make[1]: Nothing to be done for 'all'.
make[1]: Leaving directory '/home/nikola/Tools/interception-k2k'
make install
make[1]: Entering directory '/home/nikola/Tools/interception-k2k'
# If you have run `make test` then do not forget to run `make clean` after. Otherwise you may install with debug logs on.
install -D --strip -t /opt/interception out/multi-rules.h.in out/tap-rules.h.in
install: strip process terminated abnormally
install: strip process terminated abnormally
make[1]: *** [Makefile:29: install] Error 1
make[1]: Leaving directory '/home/nikola/Tools/interception-k2k'
make: *** [Makefile:34: test] Error 2

Instead I do this to run tests (albeit w/o debug output):

make clean && make && sudo make install && sudo systemctl restart udevmon.service

Problem 2 - space + home row => arrows

I want to make my space key pressed with home row keys emulate arrows. I tried:

My interception-k2k/maricn/multi-rules.h.in:

/* space + nums => F-keys */
{ .keys = { KEY_SPACE, KEY_1 }, PRESS(KEY_F1), DOWN_IFF_ALL_DOWN(2) },
{ .keys = { KEY_SPACE, KEY_2 }, PRESS(KEY_F2), DOWN_IFF_ALL_DOWN(2) },
{ .keys = { KEY_SPACE, KEY_3 }, PRESS(KEY_F3), DOWN_IFF_ALL_DOWN(2) },
{ .keys = { KEY_SPACE, KEY_4 }, PRESS(KEY_F4), DOWN_IFF_ALL_DOWN(2) },
{ .keys = { KEY_SPACE, KEY_5 }, PRESS(KEY_F5), DOWN_IFF_ALL_DOWN(2) },
{ .keys = { KEY_SPACE, KEY_6 }, PRESS(KEY_F6), DOWN_IFF_ALL_DOWN(2) },
{ .keys = { KEY_SPACE, KEY_7 }, PRESS(KEY_F7), DOWN_IFF_ALL_DOWN(2) },
{ .keys = { KEY_SPACE, KEY_8 }, PRESS(KEY_F8), DOWN_IFF_ALL_DOWN(2) },
{ .keys = { KEY_SPACE, KEY_9 }, PRESS(KEY_F9), DOWN_IFF_ALL_DOWN(2) },
{ .keys = { KEY_SPACE, KEY_0 }, PRESS(KEY_F10), DOWN_IFF_ALL_DOWN(2) },
{ .keys = { KEY_SPACE, KEY_MINUS }, PRESS(KEY_F11), DOWN_IFF_ALL_DOWN(2) },
{ .keys = { KEY_SPACE, KEY_EQUAL }, PRESS(KEY_F12), DOWN_IFF_ALL_DOWN(2) },

/* space + home row => arrow keys */
{ .keys = { KEY_SPACE, KEY_H }, PRESS_ON_DOWN(KEY_LEFT), DOWN_IFF_ALL_DOWN(2) },
{ .keys = { KEY_SPACE, KEY_K }, PRESS_ON_DOWN(KEY_UP), DOWN_IFF_ALL_DOWN(2), .repeated_key = KEY_RESERVED},
{ .keys = { KEY_SPACE, KEY_J }, PRESS_ON_DOWN(KEY_DOWN), DOWN_IFF_ALL_DOWN(2) },
{ .keys = { KEY_SPACE, KEY_L }, PRESS_ON_DOWN(KEY_RIGHT), DOWN_IFF_ALL_DOWN(2) },

My interception-k2k/maricn/multi-tap.h.in:

/* caps2esc */
{ .base_key = KEY_CAPSLOCK, .tap_key = KEY_ESC, .repeat_key = KEY_LEFTCTRL, .hold_key = KEY_LEFTCTRL, .hold_immediately = 1 },

{ .base_key = KEY_SPACE, .tap_key = KEY_SPACE, .repeat_key = KEY_RESERVED, .hold_key = KEY_RESERVED, .hold_immediately = 1 },

Problem 3 - stuck letters

Sometimes when I load interception plugin, my letter J gets stuck and doesn't output.. It doesn't get registered in evtest and when I move to another window (firefox) it keeps outputting j until i press some other key.

zsugabubus commented 3 years ago

Problem 1 - can't run make test

You have something wrong with your directory structure. Move all your “maricn/*.h.in” files into a subdirectory (as you can see with “default”, “shift2caps“, “caps2esc”).

First level (“maricn”) is the config directory. Second level (new subdirectory) will be the name of the executable that will use the “*.h.in” files inside.

Problem 2 - space + home row => arrows

Phew. I haven’t used my plugin lately, but if you go with multi rules you surely need to set nbeforedown = 2 so it switches home row key down only if both keys are down. When you release a key it sends the other, because DOWN_IFF_ALL_DOWN specifies nbeforeup = nup = -2 => we are in a toggled down state and we go into a toggled up state when not 2 keys are down (negative numbers mean not). From this, I think you will have more luck with setting them to 1 or 0.

But have you tried the following tap rules?

https://github.com/zsugabubus/interception-k2k/blob/8ec08ce6398edffde3e43ccfa868e39ba1c0ff3b/default/interception-pipe0/tap-rules.h.in#L17-L33

Just replace KEY_VIM* with KEY_SPACE and I think this is what you need.

Problem 3 - stuck letters

Did you type on the keyboard while restarting udevmon? That could cause issues.

If not, run make test, hopefully debug output can help.

maricn commented 3 years ago

Problem 1 - can't run make test

You have something wrong with your directory structure. Move all your “maricn/*.h.in” files into a subdirectory (as you can see with “default”, “shift2caps“, “caps2esc”).

Now, per your instructions, I have this repo cloned at ~/Tools/interception-k2k/ and inside I have my folder maricn which contains inteception-pipe-maricn folder with *.h.in files.

The command I have succeeded running is:

make clean && mkdir -p out/ && sudo env CONFIG_DIR=/home/nikola/Tools/interception-k2k/maricn make test

Thank you!

Problem 2 - space + home row => arrows

Just replace KEY_VIM* with KEY_SPACE and I think this is what you need.

Wow, thank you! Didn't realize that would work the way I wanted. On the first look it seems fine, but there's a huge problem (3) with stuck letters and some repeated and missed ones.

Problem 3 - stuck letters

Did you type on the keyboard while restarting udevmon? That could cause issues.

No, the command I'm running to apply the changes is:

make clean && make && sudo make install && sudo systemctl restart udevmon.service

Then I wait for a while so udevmon service restarts, but the letters still get stuck.

This happens especially when switching windows (i'm on Wayland with SwayWM). When I change focus to another window, some random key starts outputting there. So far I got letters e, n, comma, space, and even SHIFT stuck. They get unstuck when I press some other key. Also, my touchpad gets stuck sometimes.

Trying out make test and looking at the debug output didn't really help. The debug output looks fine, I wasn't able to replicate anything strange there. I also increased TIMEOUT and tried moving around my DE, but couldn't replicate that issue.

zsugabubus commented 3 years ago

there's a huge problem (3) with stuck letters and some repeated and missed ones.

I never experienced such issue on my machine (used also with Sway), but here are a few things I can think of:

some random key starts outputting there

That does not sound well. As mentioned above, please try shrinking down your config, maybe that key is one of them.