Example #1
0
 //TODO: allow for other hotkey
 internal static void RegisterKeysFor(Window window)
 {
     Contract.Requires(window != null);
     int id = window.GetHashCode() + TILDE.GetHashCode() + MOD_WIN.GetHashCode();
     var hWnd = new WindowInteropHelper(window).Handle;
     window.Closing += (_, e) => UnregisterHotKey(hWnd, id);
     RegisterHotKey(hWnd, id, MOD_WIN, TILDE);
 }
        public static void RegisterHotKey(Window w, Key key)
        {
            IntPtr handle = new WindowInteropHelper(w).Handle;
            int modifiers = 0;

            if ((key & Key.LeftAlt) == Key.LeftAlt)
                modifiers = modifiers | TextSelecting.MOD_ALT;

            if ((key & Key.LeftCtrl) == Key.LeftCtrl)
                modifiers = modifiers | TextSelecting.MOD_CONTROL;

            if ((key & Key.LeftShift) == Key.LeftShift)
                modifiers = modifiers | TextSelecting.MOD_SHIFT;

            Key k = key & ~Key.LeftCtrl & ~Key.LeftShift & ~Key.LeftAlt;
            keyId = w.GetHashCode(); // this should be a key unique ID, modify this if you want more than one hotkey
            RegisterHotKey(handle, keyId, (int)modifiers, (int)k);
        }