usbWatcher = nil function usbDeviceCallback(data) if (data["productName"] == "Kinesis Keyboard Hub") then if (data["eventType"] == "added") then hs.keycodes.setLayout("U.S. International - PC") elseif (data["eventType"] == "removed") then hs.keycodes.setLayout("Swiss French") end end end usbWatcher = hs.usb.watcher.new(usbDeviceCallback) usbWatcher:start()