QMK/Vial: communicating state to PC


A tray icon showing default/navigation/numpad states

This is a little post about a trick for displaying a programmable keyboard's state (generally just the active layer) on a computer without fiddling with firmware code.

The idea

Switching the layer doesn't emit any key presses, so there is nothing that you could catch on the computer's side by default.

However, that isn't hard to change - QMK supports layer keys inside macros, so you can define a macro that presses a "regular" key (e.g. F24) and then the layer switch key.

And if you are using this with a "toggle layer" action rather than "set base layer", you can differentiate entry/exit by creating two different macros with two different keys (or key combinations) - one for turning the layer on, and one for turning the layer off.

Example

In my layout, I have toggle-able layers for navigation and a numpad.

My layer switch macros are defined as following:

  • NAV ON: RCtrl-F23, TG(1)
  • NAV OFF: F23, TG(1)
  • NUM ON: RShift-F23, TG(3)
  • NUM OFF: F23, TG(3)

And I have the following AutoIt (v2) script to catch those key presses and change the tray icon:

#SingleInstance Force
beep := true
*F23::{
    if GetKeyState("RShift") {
        if beep SoundBeep(750)
        TraySetIcon("icons/layer_2.ico")
    }
    else if GetKeyState("RControl") {
        if beep SoundBeep(750)
        TraySetIcon("icons/layer_1.ico")
    }
    else {
        if beep SoundBeep(500)
        TraySetIcon("icons/layer_0.ico")
    }
}

And that's it, really!

Related posts:

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.