ventosus.ch Open Music Kontrollers

fakeyd

Input Event Interception Daemon

Intercept any kind of input event, mangle them and send them on (or not). Scriptable with Lua.

Your ideal companion to create macro key chains, custom layers, etc. E.g. use it to set up your lame notebook keyboard to mimick your geeky mechanical split keyboard.

Dependencies

Build / install

git clone https://git.ventosus.ch/fakeyd
cd fakeyd
meson setup build
cd build
ninja
ninja test
sudo ninja install

Invocation

fakeyd \
    -c autoshift.lua \
    -i /dev/input/by-id/usb-Dell_Dell_QuietKey_Keyboard-event-kbd

Usage

-- auto-shift uppest row to easily access special characters
-- use the numpad for nubmers
local auto_shifted <const> = {
    [keys.GRAVE]     = true, -- ~
    [keys._1]        = true, -- !
    [keys._2]        = true, -- @
    [keys._3]        = true, -- #
    [keys._4]        = true, -- $
    [keys._5]        = true, -- %
    [keys._6]        = true, -- ^
    [keys._7]        = true, -- &
    [keys._8]        = true, -- *
    [keys._9]        = true, -- (
    [keys._0]        = true, -- )
    [keys.BACKSLASH] = true, -- |
}

-- current state of shift
local shift_state = 0 

-- ev:  { type, time, time_usec, key, key_state }
local function intercept_keyboard_key(ev)
    -- store number of shift keys pressed concurrently
    if (ev.key == keys.LEFTSHIFT) or (ev.key == keys.RIGHTSHIFT) then
        shift_state = shift_state + (ev.key_state and 1 or -1)
    end

    -- only autoshift upon key press if shift is not already pressed
    local do_shift <const> = ev.key_state
        and (shift_state == 0)
        and auto_shifted[ev.key]

    if do_shift then
        keyboard_key(keys.LEFTSHIFT, true)
    end

    keyboard_key(ev.key, ev.key_state)

    if do_shift then
        keyboard_key(keys.LEFTSHIFT, false)
    end
end

local intercept_events <const> = {
    [events.KEYBOARD_KEY] = intercept_keyboard_key,
}

-- global entry point
function intercept(ev)
    local fn <const> = intercept_events[ev.type]

    if fn then
        fn(ev)
    end
end
Source