Multimedia Keys

ikbendeman said:
How do you find out which ugen to use? My usb keyboard is on my laptop and thus it is built in so I can't just unplug and plug-in and watch dmesg for it...
Laptop keyboards usually interface via PS/2, in which case your multimedia keys should work. Run xev from an xterm to get the keycodes.
 
I have the same problem the OP has. And I do not want to use X.
Any known solution?
It's your lucky day. I've been working on the same issue on my desktop for a couple of days, without success in Xorg. BUT! It works in console. Here's what I've done, YMMV:

1. Find your keyboard USB device:
# usbconfig

My usbconfig output shows:
ugen1.1: <Intel EHCI root HUB> at usbus1, cfg=0 md=HOST spd=HIGH (480Mbps) pwr=SAVE (0mA)
ugen2.1: <0x1b21 XHCI root HUB> at usbus2, cfg=0 md=HOST spd=SUPER (5.0Gbps) pwr=SAVE (0mA)
ugen3.1: <Intel EHCI root HUB> at usbus3, cfg=0 md=HOST spd=HIGH (480Mbps) pwr=SAVE (0mA)
ugen0.1: <0x8086 XHCI root HUB> at usbus0, cfg=0 md=HOST spd=SUPER (5.0Gbps) pwr=SAVE (0mA)
ugen0.2: <Logitech Gaming Mouse G502> at usbus0, cfg=0 md=HOST spd=FULL (12Mbps) pwr=ON (300mA)
ugen1.2: <vendor 0x8087 product 0x800a> at usbus1, cfg=0 md=HOST spd=HIGH (480Mbps) pwr=SAVE (0mA)
ugen3.2: <vendor 0x8087 product 0x8002> at usbus3, cfg=0 md=HOST spd=HIGH (480Mbps) pwr=SAVE (0mA)
ugen0.3: <ASUS OSD ASUS OSD> at usbus0, cfg=0 md=HOST spd=FULL (12Mbps) pwr=ON (2mA)
ugen0.4: <ASUS TEK. ASM107x> at usbus0, cfg=0 md=HOST spd=HIGH (480Mbps) pwr=SAVE (100mA)
ugen0.5: <ASUS TEK. ASM107x> at usbus0, cfg=0 md=HOST spd=HIGH (480Mbps) pwr=SAVE (100mA)
ugen0.6: <vendor 0x131d product 0x0159> at usbus0, cfg=0 md=HOST spd=FULL (12Mbps) pwr=ON (366mA)
ugen0.7: <American Power Conversion Back-UPS RS 1500G FW:865.L5 .D USB FW:L5> at usbus0, cfg=0 md=HOST spd=FULL (12Mbps) pwr=ON (2mA)
ugen0.8: <Generic Flash Card Reader/Writer> at usbus0, cfg=0 md=HOST spd=HIGH (480Mbps) pwr=ON (250mA)
ugen0.9: <Logitech Logitech G710 Keyboard> at usbus0, cfg=0 md=HOST spd=FULL (12Mbps) pwr=ON (400mA)
ugen0.10: <ASUS TEK. ASM107x> at usbus0, cfg=0 md=HOST spd=SUPER (5.0Gbps) pwr=SAVE (2mA)
ugen0.11: <ASUS TEK. ASM107x> at usbus0, cfg=0 md=HOST spd=SUPER (5.0Gbps) pwr=SAVE (2mA)


My keyboard is on ugen0.9. Keep your device number in mind.


2. Install sysutils/uhidd

Wiki documentation: https://wiki.freebsd.org/uhidd

Load the vkbd kernel module. uhidd complains that it needs it, so:
# kldload vkbd

I can get uhidd to work and catch my multimedia keys with the -ou flags. Make sure that you have either another keyboard to plug in, or that you can SSH into your box, otherwise you could end up with no functioning input if you use the wrong flags. I had to experiment around a bit to find what worked for me.

Start uhidd on the command line with additionnal -dv flags so it runs in foreground, not in daemon mode and with verbose enabled, so you'll see it if it catches your keystrokes:
# uhidd -douv /dev/ugen0.9

Use the appropriate ugenX.X from usbconfig's output in the previous step.

You'll see a new line appear each time you press a new multimedia key. My output looks like this, after pressing, in that order, mute, volume up, volume down:
uhidd 65233 - - open /usr/local/etc/uhidd.conf failed: No such file or directory
uhidd 65233 - - proceed without configuration file
ugen0.9[0]-> HID interface
ugen0.9[0]-> Report descriptor size = 65
ugen0.9[0]-> Find IN interrupt ep: 0x81 packet_size=0x8
ugen0.9[1]-> HID interface
ugen0.9[1]-> Report descriptor size = 149
ugen0.9[1]-> Find IN interrupt ep: 0x82 packet_size=0x20
ugen0.9[1]-> kbd device name: vkbdctl6
ugen0.9[1]-> HID interface task started
ugen0.9[1]-> remembered new hid key map: 0xe2 => 0x54
ugen0.9[1]-> remembered new hid key map: 0xe9 => 0x5a
ugen0.9[1]-> remembered new hid key map: 0xea => 0x5f



Keep uhidd running. All registered keys are written in /var/run/uhidd.ugenX.X/cc_keymap. Copy that file in /usr/local/etc/uhidd.conf (or your can skip this, uhidd will scan them each time they are first used, according to the wiki). Still using ugen0.9 in my example:
# cp /var/run/uhidd.ugen0.9/cc_keymap /usr/local/etc/uhidd.conf


3. Install misc/kbdscan

Run kbdscan and hit your multimedia keys. It'll give you their keycodes. It will only work in console. Not in Xorg, not even in tmux.


4. Make uhidd run as a service

You can kill uhidd for now. Edit your /etc/rc.conf to add:
vkbd_enable="YES"
uhidd_flags="-ou"
uhidd_enable="YES"


Then start the service with
# service uhidd start


5. Use the keycodes that you found with kbdscan in whatever program you use in the console.


Good luck!
 
Instructions for setting up sysutils/iichid are at: https://github.com/wulf7/iichid, as stated in the pkg-message file. https://larastechlab.blogspot.com/2020/01/i2c-touchpads-on-freebsd-130-current.html is a little less informative on setting it up.

It says load it through /boot/loader.conf so the other hid driver won't conflict with it. It also mentions reloading the driver manually as an option.

When running make config, USB (HID over USB support) is unchecked by default. It may be meant to work this way, as compiling it with this option may conflict with the default HID driver.

Multimedia keys didn't work for me. When I made a /usr/local/etc/x11/xorg.conf.d/ file for this, my arrow keys stopped working. A few of these buttons seemed to react to being pressed, but didn't do their function. When I deleted this file and restarted Xorg, my arrow keys started working again.
 
Try sysutils/iichid, it works pretty well with some keyboards I have.
Thank you very much for this post. I have spent the best part of a day trying to get this working on my bedroom mediacentre PC with TV as display.

My USB soundcard is connected to to my HiFi amplifier and a nice pair of speakers. I'm using audio/musicpd (mpd server) to play my music collection and SomaFM internet radio. And using SMPlayer for bespoke video playback, but otherwise using KODI for video entertainment. Enlightenment is my DE, and it is setup nicely now, so beautiful and functional. The last thing I needed was to get my Multimedia keys working on my main keyboard (Velocifire TKL02WS) and a small wireless keyboard and touchpad (see link below of similar product) which is ideal for controlling KODI. Both of which did not have any multimedia keys working. But now work perfectly without any other configuration in Xorg or Enlightenment. I deleted the default key bindings for XF86AudioMute, XF86AudioRaiseVolume and XF86AudioLowerVolume in Enlightenment settings panel. Now SMPlayer will pick them up for application specific volume and mute control. I assume the same will apply for KODI. This is useful to me because the mixer gadget which normally is controlled by those multimedia key bindings changes the system mixer 'vol', which affects my mpd playback volume. With application level volume control, I get exactly what I want. Super sweet setup now! :)

Only thing left now is to get Widevine support so I can watch Netflix in KODI. Until then, I may need to order a 'ROKU Express'. I'm in no hurry, but must please the spouse.

Easytone mini wireless keyboard

I could not get sysutils/uhidd to work after much trial and error and following all the instructions I could find. Thanks to frzburn for pointing out it only works in console, which I managed to achieve and test with kbdscan.

These are my steps to get it working (as root/toor user) on FreeBSD 12.2:

EDIT: I just noticed that the 'USB' port option is not required for multimedia keys to work on my wireless USB keyboard. So the binary package will do fine.

install sysutils/iichid

Code:
pkg install sysutils/iichid
ee /boot/loader.conf

add the following to the boot loader config file contents.


...
ig4_load="YES"
iicbus_load="YES"
iichid_load="YES"
hw.usb.usbhid.enable=1
....


reboot et voila.
 
That's good to know Menelkir, I was wondering if/when this would make it into FreeBSD base.

I haven't ventured into 13.0 land yet. I need to do some reading up on the new ZFS implementation yet. I feel confident with 12.x for now. Even though no dot-zero version has really let me down. Well, apart from major breakage of ipfilter in 10.0-RELEASE, which had the silver lining of forcing me onto pf. I may wait until 13.1 comes out, there are some big changes in 13 which I have not had time to read up on yet.

I updated my post above, the port option is not required. I think I just needed a reboot after the pkg version was installed to get it working.
 
There's no widevine for FreeBSD atm, but you can install a linux browser that have using this: https://github.com/mrclksr/linux-browser-installer

Wow, that sounds great. Thanks for the heads up. I will take a look at it soon. I did some pretty extensive searching around for a solution about a month or two ago, and I did not find a solution for Netflix support. I'm really glad now, that I went off-topic on my previous post. May have saved me buying that ROKU and yet another device to setup and maintain.
 
There's also a post on the forums about getting chrome or brave-browser to work to play widevine, that worked quite well for me.


But I have to admit, this link seems quicker and easier.
 
Interesting side-note to this. The iichid seems to have fixed my issue with my USB-C keyboards and FreeBSD. They work fully in Linux on the same hardware.

But on FreeBSD, prior to using iichid, they would only work if plugged into the laptop before boot and direct to the laptop USB 2.0 interface . If plugged in after boot or into the dock, they would not work at all. If unplugged, and plugged in again, not working.

And with FreeBSD with iichid setup, they now work in all these scenarios, even after repeated unplug/plug cycles. However, the modifiers do not work, which makes it almost useless. The one I'm using now, my wireless 'Velocifire TKL02WS', works fully with the wireless USB dongle, but not when using the wired USB-C cable. So iichid seems to have fixed the connectivity, but caused another issue with modifiers (two keys at once). I suspect it's to do with N-key rollover.
 
OK, more on the modifier keys not working issue. My other USB-C keyboard works fine, the shift gives me capitals and Alt +... works. It is a custom mechanical keyboard: KBDfans KBD8x.

The Velocifire TKL02WS needs a usb quirk added to /boot/loader.conf:

Code:
hw.usb.quirk.0="0x062a 0x8503 0 0xffff UQ_KBD_BOOTPROTO"

I think this is a seperate issue from the connectivity issue solved by iichid.

See this thread for more info on this and other USB keyboard issues:
 
Interesting side-note to this. The iichid seems to have fixed my issue with my USB-C keyboards and FreeBSD. They work fully in Linux on the same hardware.

But on FreeBSD, prior to using iichid, they would only work if plugged into the laptop before boot and direct to the laptop USB 2.0 interface . If plugged in after boot or into the dock, they would not work at all. If unplugged, and plugged in again, not working.

And with FreeBSD with iichid setup, they now work in all these scenarios, even after repeated unplug/plug cycles. However, the modifiers do not work, which makes it almost useless. The one I'm using now, my wireless 'Velocifire TKL02WS', works fully with the wireless USB dongle, but not when using the wired USB-C cable. So iichid seems to have fixed the connectivity, but caused another issue with modifiers (two keys at once). I suspect it's to do with N-key rollover.
Make a bug report, maybe is something easy to fix by the devs.
 
I will make some bug reports soon.

Just for clarity; I have all my keyboard issues resolved now. The sysutils/iichid port fixes multimedia keys not working on my two wireless (USB dongle) keyboards and it fixes my KBD8x USB-C connectivity issue. The usb quirk in /boot/loader.conf fixes the modifier keys not working on my Velocifire TKL02WS when used with a USB-C cable. The TKL02WS on wireless dongle does not have the modifier keys issue.
 
I have a Logitech Internet Navigator Keyboard that came with a USB to PS/2 adapter. This keyboard has the usual 104 ANSI keys, plus it has several multimedia keys.

On every FreeBSD 13.1 computer that I've tested, this keyboard's 104 ANSI keys work perfectly regardless of whether it's connected via USB or PS/2. kbdscan correctly detects all 104 ANSI keys, but it's unable to detect any of the multimedia keys.

Running X.Org's twm, xev is also able to detect all 104 ANSI keys, but it's unable to detect any of the multimedia keys when this keyboard is connected via USB. If I connect this keyboard to the same computer using PS/2, then xev is able to detect all the multimedia keys.

When this keyboard is connected using USB, usbdump produces output every time any of the multimedia keys are pressed. This indicates that FreeBSD is detecting these keystrokes via USB, but it's relaying them differently than via PS/2.

I've tried running the same version of X.Org on a different operating system, and xev was able to detect the multimedia keys via both PS/2 and USB. This suggests a problem with FreeBSD's drivers.

I've tried using window managers that offer overrides to the keyboard model detected by X.Org, but the results were the same. I've tried manually specifying the keyboard model to use in xorg.conf, but this made no difference either.

I've tried the iichid method that other users have suggested here, and I've tried the USB quirk method with this keyboard's vendor and product identifiers, but neither of these methods gave me the successes that others have enjoyed. xev still won't detect this keyboard's multimedia keys when it's connected via USB.

Regardless of whether or not the iichid or USB quirk methods are used, there's a message that appears 32 times while booting when this keyboard is connected via USB, but I haven't analyzed the source code to see if this is related:

hid_get_item: HID_ITEM_MAXUSAGE should be increased up to 16 to parse the HID report descriptor

Usable computers with PS/2 ports are becoming increasingly scarce, and I personally know several FreeBSD users who have encountered this problem as they've upgraded and/or replaced their computers. We could replace our keyboards with newer models, but given that these keyboards otherwise continue to work to our satisfaction, I'd consider this wasteful.

I'm willing to put more time into solving this problem and submitting a patch, but I'm hoping that somebody here might have some better ideas. Any helpful suggestions would be appreciated.
 
Back
Top