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

Can I fix keys with keycode 0 somehow? #27

Closed
ccoenen opened this issue Jan 26, 2022 · 17 comments
Closed

Can I fix keys with keycode 0 somehow? #27

ccoenen opened this issue Jan 26, 2022 · 17 comments

Comments

@ccoenen
Copy link

ccoenen commented Jan 26, 2022

I am now pretty happy with my current setup. I just miss a few keys that do not work. Is there even a way to get this done?

I'm using a windows server on barrier 2.4 and waynergy client configured to use uinput. I've set raw-input.offset to 8 which works well for ~75% of all my keys. I am notably missing the arrow keys (and a few more that don't bother me as much).

I've set my loglevel to 4, and I can see the keycodes that are received. My problem is: they are all 0. Is there even a way to fix this? I have no real idea how I would even start getting that in order. Even if I do not set offset, this happens, too.

Here I'm highlighting keys by how well they work (including offset=8):
grafik

🟢 green ones work exactly as they are supposed to work as far as I can tell.
🟠 orange ones return keycode 0 in the logfile.
⚪ gray ones show other weird behaviour, but I do not (yet) care about them enough to dig deeper.

@ccoenen
Copy link
Author

ccoenen commented Jan 26, 2022

I set barrier to be level Debug1, which includes keycodes sent to the client. here are the log lines for SUPER, UP, LEFT, RIGHT (all received as 0) and DOWN (received as 1):

// SUPER / WIN keydown
DEBUG1: hook: 0x0000005b 0x015b0001
DEBUG1: hook: 0x605b0000 0x015b0001
DEBUG1: hook: 0x705b0000 0x015b0001
DEBUG1: event: Key char=0, vk=0x5b, nagr=0, lParam=0x015b0001
DEBUG1: new mask: 0x2000
DEBUG1: new mask: 0x2010
DEBUG1: onKeyDown id=61419 mask=0x2010 button=0x015b
DEBUG1: send key down to "client-computer" id=61419, mask=0x2010, button=0x015b

// SUPER / WIN keyup
DEBUG1: hook: 0x0000005b 0x815b0001
DEBUG1: hook: 0x605b0000 0x815b0001
DEBUG1: hook: 0x705b0000 0x815b0001
DEBUG1: event: Key char=0, vk=0x5b, nagr=0, lParam=0x815b0001
DEBUG1: new mask: 0x2010
DEBUG1: new mask: 0x2000
DEBUG1: onKeyUp id=61419 mask=0x2000 button=0x015b
DEBUG1: send key up to "client-computer" id=61419, mask=0x2000, button=0x015b

// LEFT keydown
DEBUG1: hook: 0x00000025 0x014b0001
DEBUG1: hook: 0x60250000 0x014b0001
DEBUG1: hook: 0x70250000 0x014b0001
DEBUG1: event: Key char=0, vk=0x25, nagr=0, lParam=0x014b0001
DEBUG1: new mask: 0x2000
DEBUG1: new mask: 0x2000
DEBUG1: onKeyDown id=61265 mask=0x2000 button=0x014b
DEBUG1: send key down to "client-computer" id=61265, mask=0x2000, button=0x014b

// LEFT keyup
DEBUG1: hook: 0x00000025 0x814b0001
DEBUG1: hook: 0x60250000 0x814b0001
DEBUG1: hook: 0x70250000 0x814b0001
DEBUG1: event: Key char=0, vk=0x25, nagr=0, lParam=0x814b0001
DEBUG1: new mask: 0x2000
DEBUG1: new mask: 0x2000
DEBUG1: onKeyUp id=61265 mask=0x2000 button=0x014b
DEBUG1: send key up to "client-computer" id=61265, mask=0x2000, button=0x014b

// UP keydown
DEBUG1: hook: 0x00000026 0x01480001
DEBUG1: hook: 0x60260000 0x01480001
DEBUG1: hook: 0x70260000 0x01480001
DEBUG1: event: Key char=0, vk=0x26, nagr=0, lParam=0x01480001
DEBUG1: new mask: 0x2000
DEBUG1: new mask: 0x2000
DEBUG1: onKeyDown id=61266 mask=0x2000 button=0x0148
DEBUG1: send key down to "client-computer" id=61266, mask=0x2000, button=0x0148

// UP keyup
DEBUG1: hook: 0x00000026 0x81480001
DEBUG1: hook: 0x60260000 0x81480001
DEBUG1: hook: 0x70260000 0x81480001
DEBUG1: event: Key char=0, vk=0x26, nagr=0, lParam=0x81480001
DEBUG1: new mask: 0x2000
DEBUG1: new mask: 0x2000
DEBUG1: onKeyUp id=61266 mask=0x2000 button=0x0148
DEBUG1: send key up to "client-computer" id=61266, mask=0x2000, button=0x0148

// RIGHT keydown
DEBUG1: hook: 0x00000027 0x014d0001
DEBUG1: hook: 0x60270000 0x014d0001
DEBUG1: hook: 0x70270000 0x014d0001
DEBUG1: event: Key char=0, vk=0x27, nagr=0, lParam=0x014d0001
DEBUG1: new mask: 0x2000
DEBUG1: new mask: 0x2000
DEBUG1: onKeyDown id=61267 mask=0x2000 button=0x014d
DEBUG1: send key down to "client-computer" id=61267, mask=0x2000, button=0x014d

// RIGHT keyup
DEBUG1: hook: 0x00000027 0x814d0001
DEBUG1: hook: 0x60270000 0x814d0001
DEBUG1: hook: 0x70270000 0x814d0001
DEBUG1: event: Key char=0, vk=0x27, nagr=0, lParam=0x814d0001
DEBUG1: new mask: 0x2000
DEBUG1: new mask: 0x2000
DEBUG1: onKeyUp id=61267 mask=0x2000 button=0x014d
DEBUG1: send key up to "client-computer" id=61267, mask=0x2000, button=0x014d

// DOWN keydown
DEBUG1: hook: 0x00000028 0x01500001
DEBUG1: hook: 0x60280000 0x01500001
DEBUG1: hook: 0x70280000 0x01500001
DEBUG1: event: Key char=0, vk=0x28, nagr=0, lParam=0x01500001
DEBUG1: new mask: 0x2000
DEBUG1: new mask: 0x2000
DEBUG1: onKeyDown id=61268 mask=0x2000 button=0x0150
DEBUG1: send key down to "client-computer" id=61268, mask=0x2000, button=0x0150

// DOWN keyup
DEBUG1: hook: 0x00000028 0x81500001
DEBUG1: hook: 0x60280000 0x81500001
DEBUG1: hook: 0x70280000 0x81500001
DEBUG1: event: Key char=0, vk=0x28, nagr=0, lParam=0x81500001
DEBUG1: new mask: 0x2000
DEBUG1: new mask: 0x2000
DEBUG1: onKeyUp id=61268 mask=0x2000 button=0x0150
DEBUG1: send key up to "client-computer" id=61268, mask=0x2000, button=0x0150

@ccoenen
Copy link
Author

ccoenen commented Jan 26, 2022

here's a working log for the small latin letter "a" (which works fine and is received as keycode 38

// A keydown
DEBUG1: hook: 0x00000041 0x001e0001
DEBUG1: hook: 0x61410061 0x001e0001
DEBUG1: hook: 0x70410061 0x001e0001
DEBUG1: event: Key char=97, vk=0x41, nagr=0, lParam=0x001e0001
DEBUG1: new mask: 0x2000
DEBUG1: new mask: 0x2000
DEBUG1: onKeyDown id=97 mask=0x2000 button=0x001e
DEBUG1: send key down to "client-computer" id=97, mask=0x2000, button=0x001e

// A keyup
DEBUG1: hook: 0x00000041 0x801e0001
DEBUG1: hook: 0x61410061 0x801e0001
DEBUG1: hook: 0x70410061 0x801e0001
DEBUG1: event: Key char=97, vk=0x41, nagr=0, lParam=0x801e0001
DEBUG1: new mask: 0x2000
DEBUG1: new mask: 0x2000
DEBUG1: onKeyUp id=97 mask=0x2000 button=0x001e
DEBUG1: send key up to "client-computer" id=97, mask=0x2000, button=0x001e

@ccoenen
Copy link
Author

ccoenen commented Jan 26, 2022

Not sure if I decode this correctly, but my above log for "a" has "button=0x001e", which is decimal 30. Which would (+ offset 8) become keycode 38 in waynergy? is that correct?

The (non-working) buttons have these button hex codes => decimal codes => (esitmated incl 8 offset)
(SUPER) 0x015b => 347 => (355)
(LEFT) 0x014b => 331 => (339)
(UP) 0x0148 => 328 => (336)
(RIGHT) 0x014d => 333 => (339)
(DOWN) 0x0150 => 336 => (344)

@ccoenen
Copy link
Author

ccoenen commented Jan 26, 2022

after digging through wl_input.c for a while, I just decided to create a raw map instead, and it appears to be working:

[raw-keymap]
331=83
328=80
333=85
336=88
(wrong: see below)

I got lucky for those four in particular, because my number block already did the "right" thing. I have no idea where I would have gotton those "target" mappings otherwise. Now I'm looking for SUPER, and if that works, I'm happy for now.

I should note that I was mapping the exact number from barrier to the exact number I wanted. Offset does not seem to play a role, here.

@ccoenen
Copy link
Author

ccoenen commented Jan 26, 2022

I learned about the tool xev which shows keycodes :-)
And that I probably had the wrong "target" keycodes above. Those are for the number block. Correct keycodes should be:

[raw-keymap]
# Super Left
347=133
# LEFT
331=113
# UP
328=111
# RIGHT
333=114
# DOWN
336=116

in other words: there's no "simple" offset for these. Difference is 214, 218, 217, 219 and 220 - coincidence? Somehow I believe that I may be able to find the right ctrl, alt and super keys now, too. They are probably offset by 215 and/or 216 from their windows counterparts if that pattern above holds.

@r-c-f
Copy link
Owner

r-c-f commented Jan 26, 2022

Unfortunately the pattern doesn't really hold -- the keycodes sent by the various possible server platforms tend to align very poorly, especially once you move beyond alphanumeric keys.

@ccoenen
Copy link
Author

ccoenen commented Jan 26, 2022

Then I'll try to identify the remaining orange keys as best I can. But not tonight :-)

@r-c-f
Copy link
Owner

r-c-f commented Jan 26, 2022

For a start, /usr/include/linux/input-event-codes.h can prove somewhat enlightening, with the caveat that any layout changes you've made in GNOME can throw things off (especially if you switch between the various national layouts).

@ccoenen
Copy link
Author

ccoenen commented Jan 26, 2022

Leaving this here for me for tomorrow:
Windows Key Ids ("button" as reported by barrier):

  • AltGr -> combines 0x1d (left ctrl) 0x138 (possibly right alt? not sure?) this key is always wonky on windows, though.
  • Super R -> 0x15c
  • Menu R -> 0x15d
  • Ctrl R -> 0x11d
  • PrintScreen -> 0x137
  • ScrollLock -> not sent, used to lock to one specific scren - nice, did not know about that!
  • Pause -> 0x45
  • Ins -> 0x152
  • Del -> 0x153
  • Pos1 -> 0x147
  • End -> 0x14f
  • PgUp -> 0x149
  • PgDn -> 0x151

@ccoenen
Copy link
Author

ccoenen commented Jan 27, 2022

eh... I finished it anyway. This is as far as I will probably take it, because I can not test the other keys on my laptop with much confidence.

[raw-keymap]
offset=8
#Left
331=113
#UP
328=111
#RIGHT
333=114
#DOWN
336=116
# Super L
347=133
# Super R - just using SUPER L here, i did not have a SUPER R to test and they do not differ.
348=133
# Ctrl R
285=105
# Pause
69=127
# Ins
338=118
# Del
339=119
# Pos1
327=110
# End
335=115
# PgUp
329=112
# PgDn
337=117

This is valid and tested for: Windows 10 running barrier as server and Ubuntu 21.10 running gnome with waynergy through uinput. Both machines have german keyboard layouts.

With the combination of barrier loglevel Debug1 (look for "button=" and convert from hex to decimal) and waynergy loglevel 4 and the tool xev (look for keycode) pretty much everyone should be able to figure out further missing keycodes.

So, the keyboard now looks like this:
grafik

@r-c-f
Copy link
Owner

r-c-f commented Jan 27, 2022

To make it slightly less tedious, it should be noted that the calls to strtol() all specify 0 as a base, so you don't need to bother with hex conversion as long as you prefix with 0x.

@ccoenen
Copy link
Author

ccoenen commented Jan 27, 2022

I'm not entirely sure how to proceed here. I could close this, because my immediate need is solved. I could put thin on a wiki if you think this might be valuable for other people. I could make an .ini from it, but it's not really complete, so I do not know if this is a good thing to do. It is really specific, but at the same time may save other people some time.

@r-c-f
Copy link
Owner

r-c-f commented Jan 27, 2022

Under doc there is already a set of example xkb keycodes files contributed by others; supporting something like a config.ini.d directory would make including raw keymap snippets straightforward as well, so I'll get on implementating that.

@r-c-f
Copy link
Owner

r-c-f commented Jan 28, 2022

For now I'll close this -- it's linked from the README -- though if anything else comes please do reopen

@Kjubyte
Copy link

Kjubyte commented Apr 15, 2022

I updated the keymap so it works with current waynergy version and added some missing keys. Only tested with windows -> kwin (german layout)

Only missing AltGr and mouse buttons back and forward. Didn't found a solution for them yet.

[raw-keymap]
offset=8
offset_on_explicit=false

#Left
331=113
#UP
328=111
#RIGHT
333=114
#DOWN
336=116

# Super L
347=133
# Super R
348=134
# Ctrl R
285=105

# Pause
69=127
# PrtScn
311=107

# Ins
338=118
# Del
339=119
# Pos1
327=110
# End
335=115
# PgUp
329=112
# PgDn
337=117

# NumLock
325=77
# Num-/
309=106
# NumEnter
284=104

@MYanello
Copy link

Is there a way to map extra mouse buttons? They come through in barrier logs just as:
[2022-05-17T17:57:15] DEBUG1: onMouseDown id=4 [2022-05-17T17:57:16] DEBUG1: event: button release button=4 [2022-05-17T17:57:16] DEBUG1: onMouseUp id=4

@r0zbot
Copy link

r0zbot commented Aug 16, 2022

[raw-keymap]
offset=8
offset_on_explicit=false

#Left
331=113
#UP
328=111
#RIGHT
333=114
#DOWN
336=116

# Super L
347=133
# Super R
348=134
# Ctrl R
285=105

# Pause
69=127
# PrtScn
311=107

# Ins
338=118
# Del
339=119
# Pos1
327=110
# End
335=115
# PgUp
329=112
# PgDn
337=117

# NumLock
325=77
# Num-/
309=106
# NumEnter
284=104

Just adding that this also works for the ABNT2 PT-BR layout (Windows to Gnome), but I needed to add the following id-keymaps to get the ? and / keys working. For some reason, while using raw-keymap, those particular keys just couldn't be remapped at all (they always send keycode 123). Also, while I was at it, I also added the media keys, in case anyone is interested:

[id-keymap]
# /
47=97
# ? 
63=97

# volume mute
57517=121
# volume down
57518=122
# volume up
57519=123

# media stop
57522=174
# media back
57521=173
# media play
57523=172
# media next
57520=171

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants