From fe3c744c6990291b75068917e781a67d7676c217 Mon Sep 17 00:00:00 2001 From: Jean Helou Date: Mon, 23 Oct 2017 21:52:42 +0200 Subject: [PATCH] Implement -location flag Includes locationId in the keyboards identifiers (defaults to false) Note that the locationId changes when you plug a keyboard in a different port. Therefore using the locationId in the keyboards identifiers means the configured language will be associated to a keyboard on a specific port. fixes #6 --- autokbisw/IOKeyEventMonitor.swift | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/autokbisw/IOKeyEventMonitor.swift b/autokbisw/IOKeyEventMonitor.swift index d3da664..cfef671 100644 --- a/autokbisw/IOKeyEventMonitor.swift +++ b/autokbisw/IOKeyEventMonitor.swift @@ -80,13 +80,15 @@ final internal class IOKeyEventMonitor { let locationId = String(describing: IOHIDDeviceGetProperty(senderDevice, kIOHIDLocationIDKey as CFString)); let uniqueId = String(describing: IOHIDDeviceGetProperty(senderDevice, kIOHIDUniqueIDKey as CFString)); - let keyboard = "\(product) - [\(vendorId)-\(productId)-\(manufacturer)-\(serialNumber)]"; + let keyboard = + selfPtr.userOptions.useLocation ? + "\(product)-[\(vendorId)-\(productId)-\(manufacturer)-\(serialNumber)-\(locationId)]" : + "\(product)-[\(vendorId)-\(productId)-\(manufacturer)-\(serialNumber)]"; if(selfPtr.userOptions.verbosity >= UserOptions.TRACE){ print("received event from keyboard \(keyboard) - \(locationId) - \(uniqueId)"); } - selfPtr.onKeyboardEvent(keyboard: keyboard); - + selfPtr.onKeyboardEvent(keyboard: keyboard); } IOHIDManagerRegisterInputValueCallback( hidManager, myHIDKeyboardCallback, context);