             else {
                 self.keyCode = nil
             }
+        }
+        
+        NSEvent.addGlobalMonitorForEvents(matching: NSEventMask.flagsChanged, handler: flagsChangedHandler)
+        NSEvent.addLocalMonitorForEvents(matching: NSEventMask.flagsChanged, handler: {(evevt: NSEvent!) -> NSEvent? in
+            flagsChangedHandler(evevt)
+            return evevt
         })
+        
         
     }
 }

            print("アクセシビリティに設定されました")
            
            self.watch()
            
//            addLaunchAtStartup()
            loginItem.state = 1
        }
    }
    
    func watch () {
        let masks = [
            NSEventMask.keyDown,
            NSEventMask.keyUp,

            NSEventMask.scrollWheel
            // NSEventMask.MouseMovedMask,
        ]
        
        for mask in masks {
            NSEvent.addGlobalMonitorForEvents(matching: mask, handler: resetGlobalHandler)
            NSEvent.addLocalMonitorForEvents(matching: mask, handler: resetLocalHandler)
        }
        
        let flagsChangedHandler = {(evevt: NSEvent!) -> Void in
            if evevt.keyCode == 55 { // 右コマンドキー
                if evevt.modifierFlags.contains(.command) {
                    self.keyCode = 55
