Skip to content

Instantly share code, notes, and snippets.

@fhemberger
Created November 21, 2021 20:12
Show Gist options
  • Select an option

  • Save fhemberger/57ccfc6d228cfb37552cdfb11a09445c to your computer and use it in GitHub Desktop.

Select an option

Save fhemberger/57ccfc6d228cfb37552cdfb11a09445c to your computer and use it in GitHub Desktop.

Revisions

  1. fhemberger created this gist Nov 21, 2021.
    16 changes: 16 additions & 0 deletions init.lua
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,16 @@
    local usbLogger = hs.logger.new('usb', 'debug')

    function configureKeyboard(data)
    -- Uncomment the "usbLogger" line below, plug in the USB keyboard and update the USB vendor and product ID
    local isKeyboardAffected = data.vendorID == 9610 and data.productID == 89
    -- usbLogger.df("eventType %s, pname %s, vname %s, vId %s, pId %s, keyboardAffected %s", data.eventType, data.productName, data.vendorName, data.vendorID, data.productID, isKeyboardAffected)
    if isKeyboardAffected and data.eventType == "added" then
    hs.keycodes.setLayout("U.S.")
    end
    if isKeyboardAffected and data.eventType == "removed" then
    hs.keycodes.setLayout("German")
    end
    end

    local keyboardWatcher = hs.usb.watcher.new(configureKeyboard)
    keyboardWatcher:start()