 
 final internal class IOKeyEventMonitor {
   private let hidManager: IOHIDManager
-  
+  fileprivate let MAPPINGS_DEFAULTS_KEY = "keyboardISMapping"
   fileprivate let notificationCenter: CFNotificationCenter
   fileprivate let userOptions: UserOptions
   fileprivate var lastActiveKeyboard: String = ""
   fileprivate var kb2is: [String: TISInputSource] = [String: TISInputSource]()
+  fileprivate var defaults: UserDefaults = UserDefaults.standard;
 
   init? ( usagePage: Int, usage: Int, _userOptions: UserOptions) {
     userOptions = _userOptions;


extension IOKeyEventMonitor {
  
  
  
  func restoreInputSource(keyboard: String) -> Void {
    if let targetIs = kb2is[keyboard] {
      if(userOptions.verbosity >= UserOptions.DEBUG){

    notificationCenter = CFNotificationCenterGetDistributedCenter();
    let deviceMatch: CFMutableDictionary = [kIOHIDDeviceUsageKey: usage, kIOHIDDeviceUsagePageKey: usagePage] as NSMutableDictionary
    IOHIDManagerSetDeviceMatching( hidManager, deviceMatch);
    self.loadMappings()
  }

  deinit {
    self.saveMappings();
    let context = UnsafeMutableRawPointer(Unmanaged.passUnretained(self).toOpaque());
    IOHIDManagerRegisterInputValueCallback( hidManager, Optional.none , context);
    CFNotificationCenterRemoveObserver(notificationCenter, context, CFNotificationName(kTISNotifySelectedKeyboardInputSourceChanged), nil);
