elementary / switchboard-plug-keyboard

Switchboard Keyboard Plug
GNU General Public License v2.0
28 stars 22 forks source link

~ appears as < for Logitech MX Keys #298

Open neofight78 opened 4 years ago

neofight78 commented 4 years ago

I have a Russian edition Logitech MX Keys keyboard and I am using the Russian and English (US) layouts.

The English (US) layout seems to work fine except the ` & ~ key appears as < & >. I googled the following fix:

setxkbmap -option apple:badmap

Which seems to sort it out, but it seems the change doesn't always survive layout switches, reboots etc.

In any case this should be a problem I can sort out via the keyboard settings UI.

neofight78 commented 4 years ago

@davidmhewitt Any chance you could take a look at this as this month's sponsorship item?

davidmhewitt commented 4 years ago

Thanks for the sponsorship. I think I'll struggle to help because it is a hardware specific issue, but I have some questions.

1) Have you ever used this keyboard on Mac hardware or on MacOS? 2) Have you tried the alternative layouts in the keyboard settings UI? Like "English (US) -> English (Macintosh)"?

neofight78 commented 4 years ago

Understood, I appreciate the help however far you get.

  1. Yes, it works fine on a Mac. It wasn't automatically recognised, but the wizard popped up and I was asked to press the key immediately to the right of the left shift key. From that macOS magically worked out what they layout was.

  2. Yes, I tried a whole bunch of layouts and English (US) seems the closest.

Does the command I mentioned give any clues? Could it be added to the UI somehow? Alternatively a way to remap single keys might be ok?

neofight78 commented 4 years ago

Found this: https://askubuntu.com/questions/843590/key-keycode-49-and-key-keycode-94-are-inverted-on-macbookpro-keyboar/844931#844931

Is it something that could be exposed via the settings UI?

davidmhewitt commented 4 years ago

I think it's quite unlikely that any new UI to fix driver issues with keyboard is going to be accepted.

However, I can help you investigate more and maybe we'll find a more permanent fix. We might find that there's some config that we can submit to a hardware database that fixes this on all linux distros.

You'll need to install libinput-tools if you haven't already. You can do this with sudo apt install libinput-tools

Then if you run sudo libinput list-devices, you should get a list of the input devices attached to the system.

Find your keyboard in this list and take note of its Kernel: line. It will be something like /dev/input/event0.

Please show me the output of udevadm info /dev/input/event0 (replace event0 with your value from the previous command).

Now install evtest (sudo apt install evtest)

Run it with sudo evtest /dev/input/event0 (again, replace event0)

Press the keys you are having problems with (~ and < ? ) and use CTRL+C to exit. Please copy and paste the output from this too so I can see.

neofight78 commented 4 years ago

Ok, this is run without the above fix I mentioned applied:

udevadm info /dev/input/event12

P: /devices/virtual/misc/uhid/0005:046D:B35B.0002/input/input12/event12
N: input/event12
E: BACKSPACE=guess
E: DEVNAME=/dev/input/event12
E: DEVPATH=/devices/virtual/misc/uhid/0005:046D:B35B.0002/input/input12/event12
E: ID_BUS=bluetooth
E: ID_INPUT=1
E: ID_INPUT_KEY=1
E: ID_INPUT_KEYBOARD=1
E: LIBINPUT_DEVICE_GROUP=5/46d/b35b:04:33:C2:6B:D8:F6
E: MAJOR=13
E: MINOR=76
E: SUBSYSTEM=input
E: TAGS=:power-switch:
E: USEC_INITIALIZED=364764154
E: XKBLAYOUT=us,ru
E: XKBVARIANT=,

There is just one key I am having problems with. This is what I get for what should be the back tick (or tilde when holding shift)

sudo evtest /dev/input/event12

Input driver version is 1.0.1
Input device ID: bus 0x5 vendor 0x46d product 0xb35b version 0x11
Input device name: "MX Keys Keyboard"
Supported events:
  Event type 0 (EV_SYN)
  Event type 1 (EV_KEY)
    Event code 1 (KEY_ESC)
    Event code 2 (KEY_1)
    Event code 3 (KEY_2)
    Event code 4 (KEY_3)
    Event code 5 (KEY_4)
    Event code 6 (KEY_5)
    Event code 7 (KEY_6)
    Event code 8 (KEY_7)
    Event code 9 (KEY_8)
    Event code 10 (KEY_9)
    Event code 11 (KEY_0)
    Event code 12 (KEY_MINUS)
    Event code 13 (KEY_EQUAL)
    Event code 14 (KEY_BACKSPACE)
    Event code 15 (KEY_TAB)
    Event code 16 (KEY_Q)
    Event code 17 (KEY_W)
    Event code 18 (KEY_E)
    Event code 19 (KEY_R)
    Event code 20 (KEY_T)
    Event code 21 (KEY_Y)
    Event code 22 (KEY_U)
    Event code 23 (KEY_I)
    Event code 24 (KEY_O)
    Event code 25 (KEY_P)
    Event code 26 (KEY_LEFTBRACE)
    Event code 27 (KEY_RIGHTBRACE)
    Event code 28 (KEY_ENTER)
    Event code 29 (KEY_LEFTCTRL)
    Event code 30 (KEY_A)
    Event code 31 (KEY_S)
    Event code 32 (KEY_D)
    Event code 33 (KEY_F)
    Event code 34 (KEY_G)
    Event code 35 (KEY_H)
    Event code 36 (KEY_J)
    Event code 37 (KEY_K)
    Event code 38 (KEY_L)
    Event code 39 (KEY_SEMICOLON)
    Event code 40 (KEY_APOSTROPHE)
    Event code 41 (KEY_GRAVE)
    Event code 42 (KEY_LEFTSHIFT)
    Event code 43 (KEY_BACKSLASH)
    Event code 44 (KEY_Z)
    Event code 45 (KEY_X)
    Event code 46 (KEY_C)
    Event code 47 (KEY_V)
    Event code 48 (KEY_B)
    Event code 49 (KEY_N)
    Event code 50 (KEY_M)
    Event code 51 (KEY_COMMA)
    Event code 52 (KEY_DOT)
    Event code 53 (KEY_SLASH)
    Event code 54 (KEY_RIGHTSHIFT)
    Event code 55 (KEY_KPASTERISK)
    Event code 56 (KEY_LEFTALT)
    Event code 57 (KEY_SPACE)
    Event code 58 (KEY_CAPSLOCK)
    Event code 59 (KEY_F1)
    Event code 60 (KEY_F2)
    Event code 61 (KEY_F3)
    Event code 62 (KEY_F4)
    Event code 63 (KEY_F5)
    Event code 64 (KEY_F6)
    Event code 65 (KEY_F7)
    Event code 66 (KEY_F8)
    Event code 67 (KEY_F9)
    Event code 68 (KEY_F10)
    Event code 69 (KEY_NUMLOCK)
    Event code 70 (KEY_SCROLLLOCK)
    Event code 71 (KEY_KP7)
    Event code 72 (KEY_KP8)
    Event code 73 (KEY_KP9)
    Event code 74 (KEY_KPMINUS)
    Event code 75 (KEY_KP4)
    Event code 76 (KEY_KP5)
    Event code 77 (KEY_KP6)
    Event code 78 (KEY_KPPLUS)
    Event code 79 (KEY_KP1)
    Event code 80 (KEY_KP2)
    Event code 81 (KEY_KP3)
    Event code 82 (KEY_KP0)
    Event code 83 (KEY_KPDOT)
    Event code 85 (KEY_ZENKAKUHANKAKU)
    Event code 86 (KEY_102ND)
    Event code 87 (KEY_F11)
    Event code 88 (KEY_F12)
    Event code 89 (KEY_RO)
    Event code 90 (KEY_KATAKANA)
    Event code 91 (KEY_HIRAGANA)
    Event code 92 (KEY_HENKAN)
    Event code 93 (KEY_KATAKANAHIRAGANA)
    Event code 94 (KEY_MUHENKAN)
    Event code 95 (KEY_KPJPCOMMA)
    Event code 96 (KEY_KPENTER)
    Event code 97 (KEY_RIGHTCTRL)
    Event code 98 (KEY_KPSLASH)
    Event code 99 (KEY_SYSRQ)
    Event code 100 (KEY_RIGHTALT)
    Event code 102 (KEY_HOME)
    Event code 103 (KEY_UP)
    Event code 104 (KEY_PAGEUP)
    Event code 105 (KEY_LEFT)
    Event code 106 (KEY_RIGHT)
    Event code 107 (KEY_END)
    Event code 108 (KEY_DOWN)
    Event code 109 (KEY_PAGEDOWN)
    Event code 110 (KEY_INSERT)
    Event code 111 (KEY_DELETE)
    Event code 113 (KEY_MUTE)
    Event code 114 (KEY_VOLUMEDOWN)
    Event code 115 (KEY_VOLUMEUP)
    Event code 116 (KEY_POWER)
    Event code 117 (KEY_KPEQUAL)
    Event code 119 (KEY_PAUSE)
    Event code 121 (KEY_KPCOMMA)
    Event code 122 (KEY_HANGUEL)
    Event code 123 (KEY_HANJA)
    Event code 124 (KEY_YEN)
    Event code 125 (KEY_LEFTMETA)
    Event code 126 (KEY_RIGHTMETA)
    Event code 127 (KEY_COMPOSE)
    Event code 128 (KEY_STOP)
    Event code 129 (KEY_AGAIN)
    Event code 130 (KEY_PROPS)
    Event code 131 (KEY_UNDO)
    Event code 132 (KEY_FRONT)
    Event code 133 (KEY_COPY)
    Event code 134 (KEY_OPEN)
    Event code 135 (KEY_PASTE)
    Event code 136 (KEY_FIND)
    Event code 137 (KEY_CUT)
    Event code 138 (KEY_HELP)
    Event code 183 (KEY_F13)
    Event code 184 (KEY_F14)
    Event code 185 (KEY_F15)
    Event code 186 (KEY_F16)
    Event code 187 (KEY_F17)
    Event code 188 (KEY_F18)
    Event code 189 (KEY_F19)
    Event code 190 (KEY_F20)
    Event code 191 (KEY_F21)
    Event code 192 (KEY_F22)
    Event code 193 (KEY_F23)
    Event code 194 (KEY_F24)
    Event code 240 (KEY_UNKNOWN)
  Event type 4 (EV_MSC)
    Event code 4 (MSC_SCAN)
  Event type 17 (EV_LED)
    Event code 0 (LED_NUML) state 0
    Event code 1 (LED_CAPSL) state 0
    Event code 2 (LED_SCROLLL) state 0
    Event code 3 (LED_COMPOSE) state 0
    Event code 4 (LED_KANA) state 0
Key repeat handling:
  Repeat type 20 (EV_REP)
    Repeat code 0 (REP_DELAY)
      Value    250
    Repeat code 1 (REP_PERIOD)
      Value     33
Properties:
Testing ... (interrupt to exit)
Event: time 1596264841.428558, type 4 (EV_MSC), code 4 (MSC_SCAN), value 70064
Event: time 1596264841.428558, type 1 (EV_KEY), code 86 (KEY_102ND), value 1
Event: time 1596264841.428558, -------------- SYN_REPORT ------------
<Event: time 1596264841.430298, type 4 (EV_MSC), code 4 (MSC_SCAN), value 70064
Event: time 1596264841.430298, type 1 (EV_KEY), code 86 (KEY_102ND), value 0
Event: time 1596264841.430298, -------------- SYN_REPORT ------------
Event: time 1596264842.510308, type 4 (EV_MSC), code 4 (MSC_SCAN), value 700e0
Event: time 1596264842.510308, type 1 (EV_KEY), code 29 (KEY_LEFTCTRL), value 1
Event: time 1596264842.510308, -------------- SYN_REPORT ------------
Event: time 1596264842.645392, type 4 (EV_MSC), code 4 (MSC_SCAN), value 70006
Event: time 1596264842.645392, type 1 (EV_KEY), code 46 (KEY_C), value 1
Event: time 1596264842.645392, -------------- SYN_REPORT ------------
davidmhewitt commented 4 years ago

Hey thanks, that's really interesting and helpful.

The backtick key you're pressing is in the top left of the keyboard, above tab?

It looks like your Logitech keyboard is pretending to be an Apple keyboard. I found a post on Reddit that I can't find the link to now that said that if it's been connected to a Mac running the Logitech config software, then the keyboard firmware switches into some kind of "Mac mode". Equally, if you connect it to a Windows PC running the Logitech software, it switches back. Do you have a Windows PC or partition you could try this with and see if it makes any difference when you next use it on elementary?

Or, do you have an alternative way to connect it to elementary OS that isn't bluetooth? Does it have the ability to be wired or connect via a USB dongle that isn't bluetooth?

I think we can probably tell the kernel to remap these keys, but I don't want to submit these fixes to the kernel or systemd if they're potentially going to mess up MX Keys keyboards in "Windows mode".

neofight78 commented 4 years ago

No, it's to the right of the left shift key (see below). It's an interesting theory about the modes, but it doesn't quite match what I am seeing 100%. You'll see next to the space bar there are two keys that when connected to my Mac are Opt & Cmd, but when connected to elementary OS (on PC hardware) are Start & Alt. i.e. the position of the super key changes. So presumably the mode is already being switched?

I'll try with the usb dongle shortly, a Windows machine will take a bit longer though. The first thing I did with my ThinkCentre Tiny was to overwrite Windows with elementary OS :)

CleanShot 2020-08-01 at 21 01 53

neofight78 commented 4 years ago

Ok, so connecting via the USB dongle instead of bluetooth makes no difference. I'll try testing with Windows a bit later. Ah, I should mention that I didn't install any Logitech software on my Mac.

davidmhewitt commented 4 years ago

Could you find the /dev/input/eventX path of your keyboard again (it sometimes changes) and run the following and copy the output:

cat /sys/class/input/eventX/device/modalias (replace eventX)

I'll prepare a config file that will remap that key at a hardware level that you can try.

neofight78 commented 4 years ago

Here it is:

input:b0005v046DpB35Be0011-e0,1,4,11,14,k71,72,73,74,75,77,79,7A,7B,7C,7D,7E,7F,80,81,82,83,84,85,86,87,88,89,8A,B7,B8,B9,BA,BB,BC,BD,BE,BF,C0,C1,C2,F0,ram4,l0,1,2,3,4,sfw
davidmhewitt commented 4 years ago

Ok, create /etc/udev/hwdb.d/10-mx-keys.hwdb and put the following content:

evdev:input:b0005v046DpB35B*
  KEYBOARD_KEY_70064=grave

I'm not sure if the directory exists by default, so you may need to do this first: sudo mkdir -p /etc/udev/hwdb.d

If you're not familiar with writing files into folders you need administrator permission for, you can do this with nano like this:

sudo nano /etc/udev/hwdb.d/10-mx-keys.hwdb

Then paste the contents from above and save and quit with CTRL+O then CTRL+X.

Once this is done, reboot and see if it helps.

neofight78 commented 4 years ago

Yes, that seems to solve it, thank you! Is this something that can be submitted somewhere to help (hopefully) more people than just me?

davidmhewitt commented 4 years ago

If you can try out the theory of the keyboard behaving differently after it's been used on Windows with the Logitech software. Run evtest commands again from above and see if there is a different scancode when you press that key.

If there's no difference to the 70064 scancode, then I'll submit this to the necessary place so that this can be used by all Linux distributions in the future.

This config file should work for you on other Linux distributions too should you decide to switch away from elementary in the future.

Thanks again for the sponsorship!

neofight78 commented 4 years ago

Great, thanks for your help. It's very much appreciated. I'll test out the Windows theory as soon as I get a chance.