Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configure via device ids #55

Closed
kooskaspers opened this issue Nov 20, 2021 · 10 comments
Closed

Configure via device ids #55

kooskaspers opened this issue Nov 20, 2021 · 10 comments
Labels
2.0 bug Something isn't working enhancement New feature or request

Comments

@kooskaspers
Copy link

I'm having problems creating a config file.
My keyboard is listed as "Apple Inc. Apple Internal Keyboard / Trackpad".
Since this keyboard name contains a forward slash, I'm unable to create a config file, since it's not following the UNIX philosophy:

touch Apple\ Inc.\ Apple\ Internal\ Keyboard\ \/\ Trackpad.cfg
touch: cannot touch 'Apple Inc. Apple Internal Keyboard / Trackpad.cfg': No such file or directory

Do you have any ideas supporting different ways of specifying keyboard id-s? Like the path of a device?:
Apple Inc. Apple Internal Keyboard / Trackpad

@kooskaspers
Copy link
Author

kooskaspers commented Nov 20, 2021

And by the way; what a great tool.

Just migrated my keymap from interception tools (https://gitlab.com/interception/linux/tools) to keyd.
From this script:

#include <stdio.h>
#include <stdlib.h>

#include <unistd.h>
#include <linux/input.h>

int read_event(struct input_event *event)
{
  return fread(event, sizeof(struct input_event), 1, stdin) == 1;
}

void write_event(const struct input_event *event)
{
  if (fwrite(event, sizeof(struct input_event), 1, stdout) != 1)
    exit(EXIT_FAILURE);
}

int main(void)
{
  int use_arrow_keys = 0;
  struct input_event input;
  setbuf(stdin, NULL), setbuf(stdout, NULL);
  while (read_event(&input))
  {
    if (input.type == EV_MSC && input.code == MSC_SCAN)
      continue;
    if (input.type != EV_KEY)
    {
      write_event(&input);
      continue;
    }
   if (use_arrow_keys)
    {
      if (input.code == KEY_CAPSLOCK)
      {
        if (input.value == 0) {
          use_arrow_keys = 0;
          continue;
        }

        if (input.value == 1 || input.value == 2) {
          continue;
        }
      }
    }
    else
    {
      if (input.code == KEY_CAPSLOCK)
      {
        if (input.value == 1 || input.value == 2) {
          use_arrow_keys = 1;
          continue;
        }

        if (input.value == 0) {
          continue;
        }
      }
    }

    if (use_arrow_keys) {
      if (input.code == KEY_K) {
        input.code = KEY_UP;
      }

      if (input.code == KEY_J) {
        input.code = KEY_DOWN;
      }

      if (input.code == KEY_H) {
        input.code = KEY_LEFT;
      }

      if (input.code == KEY_L) {
        input.code = KEY_RIGHT;
      }

      if (input.code == KEY_I) {
        input.code = KEY_HOME;
      }

      if (input.code == KEY_O) {
        input.code = KEY_END;
      }

      if (input.code == KEY_P) {
        input.code = KEY_PAGEDOWN;
      }

      if (input.code == KEY_U) {
        input.code = KEY_PAGEUP;
      }

      if (input.code == KEY_BACKSPACE) {
        input.code = KEY_DELETE;
      }
    }

    // volgorde is hier erg belangrijk

    if (input.code == KEY_LEFTCTRL)
    {
      input.code = KEY_RIGHTALT;
    }

    
    // LEFT ALT > RIGHT META
    if (input.code == KEY_LEFTALT)
    {
      input.code = KEY_RIGHTMETA;
    }
    
    
    // LEFT META > LEFT CTRL
    if (input.code == KEY_LEFTMETA)
    {
      input.code = KEY_RIGHTCTRL;
    }

    // knop naast linker shift  > LEFT SHIFT
    if (input.code == KEY_102ND)
    {
      input.code = KEY_LEFTSHIFT;
    }


    //
    // CAPSLOCK > ESCAPE
    //if (input.code == KEY_CAPSLOCK)
    //{
    //  input.code = KEY_ESC;
    //}


    // 102ND > COMPOSE
    //if (input.code == KEY_102ND)
    //{
    //  input.code = KEY_COMPOSE;
    //}

    write_event(&input);
  }
}

to:

control = alt
meta = control
alt = meta
rightmeta = control
102nd = shift

#capslock = layer(vim)
#overload is beter, want: overload(whenheld, whentapped)
capslock = overload(vim, capslock)

[vim]
k = up
j = down
h = left
l = right
i = home
o = end
p = pagedown
u = pageup
backspace = delete
shift = shift

Props!

@canadaduane
Copy link
Contributor

Coming from Interception Tools, I too felt it was a bit odd that the filename was the human name of the device.

In addition to the above issue, I also wish there were a way to:

  1. Pattern match on device name or device ID or device path
  2. Capability match (e.g. "this device can send KEY_A and KEY_LEFTALT", this device is NOT also a mouse)

@rvaiya
Copy link
Owner

rvaiya commented Nov 20, 2021

Do you have any ideas supporting different ways of specifying keyboard id-s? Like the path of a device?

This was a clumsy initial design decision. I plan on allowing the user to specify product/vendor id pairs to which the config applies within the config file itself in an upcoming commit. This will also allow configs to apply to more than one keyboard without resorting to symlinking.

Pattern match on device name or device ID or device path

I'm not convinced about the utility of pattern matching. Different devices can have similar names, it makes more sense to let the user explcitly specify the device(s) of interest in the form of product ids.

Capability match (e.g. "this device can send KEY_A and KEY_LEFTALT", this device is NOT also a mouse)

Keyd actually creates a separate virtual pointer for this reason. udev will identify anything which can produce REL events as a mouse, which causes certain pieces of software to behave incorrectly. I'm not sure exposing the specific key events of the uinput device makes sense though. Have you encountered a specific problem?

@canadaduane
Copy link
Contributor

canadaduane commented Nov 20, 2021

Have you encountered a specific problem?

I want to package keyd as a deb, and it isn't clear to me what I should do as a reasonable default setting. The best option so far is "default.cfg" but I'm not sure that suits all users.

@rvaiya
Copy link
Owner

rvaiya commented Nov 20, 2021

I want to package keyd as a deb, and it isn't clear to me what I should do as a reasonable default setting.

I meant with respect to needing to specify the capabilities of the device.

Thanks for taking the trouble to package it. That has been on my todo list for a while.

The best option so far is "default.cfg" but I'm not sure that suits all users.

I would advise against even creating 'default.cfg' since it causes all keyboard events to be funnelled through keyd's virtual device. This shouldn't be a problem most of the time, but it may conflict with other (potentially evdev based) tools the user has installed. You may want to include some examples in the config directory though.

@kooskaspers
Copy link
Author

I want to package keyd as a deb, and it isn't clear to me what I should do as a reasonable default setting.

I meant with respect to needing to specify the capabilities of the device.

Thanks for taking the trouble to package it. That has been on my todo list for a while.

The best option so far is "default.cfg" but I'm not sure that suits all users.

I would advise against even creating 'default.cfg' since it causes all keyboard events to be funnelled through keyd's virtual device. This shouldn't be a problem most of the time, but it may conflict with other (potentially evdev based) tools the user has installed. You may want to include some examples in the config directory though.

Using the default.cfg will conflict for me as well, when using an external keyboard which I flashed and programmed already with the qmk firmware. Product/vendor id pairs would be great!

@rvaiya
Copy link
Owner

rvaiya commented Nov 23, 2021

This is in the pipeline along with #59. I need to clean up some of the config code for this and a few related changes.

@rvaiya rvaiya changed the title Support for something else than the keyboard name Configure via device ids Nov 25, 2021
@rvaiya rvaiya added bug Something isn't working enhancement New feature or request 2.0 labels Nov 25, 2021
@rvaiya
Copy link
Owner

rvaiya commented Dec 27, 2021

This should be implemented in the latest version. Sorry for the delay.

@kooskaspers
Copy link
Author

No worries mate!

@rvaiya
Copy link
Owner

rvaiya commented Dec 28, 2021

I'm closing this for now, feel free to file another issue if you encounter any problems :).

@rvaiya rvaiya closed this as completed Dec 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2.0 bug Something isn't working enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants