From 396ba133e421a12e6f523f14d7a18cade7fc94a3 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Mon, 19 Sep 2022 20:11:01 +0200 Subject: keyboard_layout: Try to change keyboard layout on keyboard device change Try to detect when any keyboard is plugged in by looking at its "productName" and checking to see if it contains the word "keyboard". If so, change the keyboard layout between the preferred for internal and external keyboards. --- keyboard_layout.lua | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'keyboard_layout.lua') diff --git a/keyboard_layout.lua b/keyboard_layout.lua index 34404b7..9e6e1aa 100644 --- a/keyboard_layout.lua +++ b/keyboard_layout.lua @@ -25,6 +25,14 @@ keyboard_usb_watcher = hs.usb.watcher.new(function(event) return end + local product_name_contains_word_keyboard = string.find( + string.lower(event['productName']), + "keyboard" + ) + if not product_name_contains_word_keyboard then + return + end + if event['eventType'] == 'added' then hs.keycodes.setLayout('U.S.') elseif event['eventType'] == 'removed' then -- cgit v1.2.3