Keyboard Builders' Digest
Save 5% at Typeractive! Code: KBDNEWS
Keyboard Builders' Digest / Projects

How to detect host OS in QMK

A clever way to automatically detect host OS in QMK based on USB setup pockets – shared by u/kapji.

KBD.news
Published August 30, 2022
Creators! Feel free to tip me off about your keyboard related projects to bring them to 150K readers.

Ruslan Sayfutdinov aka KapJI shared his trick to detect host OS in QMK.

I found a way to detect host OS based on USB setup packets in keyboard firmware without need to install any extra tools – kapji.

What is this good for? E.g. you can automatically swap Ctrl and Cmd on Mac and Windows or create platform independent macros for copy-paste. Here is an example by kapji. Some layouts like Hands Down have a manual switch for that, now it can be done automatically.

This method uses the wLength field in get_descriptor packets during the USB setup sequence. Different OSes have different number of such packets and some patterns in these values. The author's guess is that it depends on the implementation of USB stack. For example, Linux always sets it to 0xFFFF.

The idea is coming from an Arduino project called FingerprintUSBHost.

According to the author, this approach can detect Windows, Linux, MacOS and iOS. ChromeOS and Android are both identified as Linux (since they're both using the Linux USB stack.)

Do you like this post? Share, donate, subscribe, tip me off!

Published on Tue 30th Aug 2022. Featured in KBD #92 (source).


Tags: QMKtipOS

Related

Why on earth should a keyboard do that?

Nick Brassel (@tzarc), one of QMK’s Directors, wasn’t satisfied with keyboards only having switches and an indicator LED or three.

Caps Word and other QMK tips

A QMK keymap with short blog posts by Mental_General_5445 explaining tricks like autocorrection, Caps Word, getting Shift keys right, etc.

QMK RGB Matrix configuration

The focus of Sadek Baroudi's tutorial is how to properly configure RGB Matrix especially for non-trivial ergo keyboards with angles and column stagger.

TB3S trackball

A small DIY trackball device, based around an Elite-Pi controller and a PMW3360 sensor: TB3S by Wimads.

Luna - a QMK keyboard pet

Luna is a QMK keyboard pet by HellSingCoder reacting to your typing speed and same layer states (video, git).

QMK's sound features

Help with QMK startup sounds by psychephylax.

×
top