Beispiel #1
0
        public void RegisterHotKey(string Purpose, KeyModifiers modifiers, Keys vk, Action <HotKey> OnPressed)
        {
            HotKey key = RegisteredHotKeys.SingleOrDefault(o => o.Purpose == Purpose);

            if (key == null)
            {
                key = new HotKey()
                {
                    Purpose = Purpose, id = id, fsModifiers = modifiers, vk = vk, OnPressed = OnPressed
                };
                bool issuccess = WinApiMethods.RegisterHotKey(windowHandle, key.id, key.fsModifiers, (uint)key.vk);
                if (!issuccess)
                {
                    key = null;
                    Win32Exception ex = new Win32Exception(Marshal.GetLastWin32Error());
                    if (ex.Message == "Hot key is already registered")
                    {
                        throw ex;
                    }
                }
                else
                {
                    RegisteredHotKeys.Add(key);
                    id++;
                }
            }
            else
            {
                throw new AlreadyMappedException(key);
            }
        }
        public void RegisterClipboardEvent(string Purpose, Action OnClipboardDraw)
        {
            ClipboardEventListenerWindow clipboardEventListenerWindow = RegisteredClipboardEventListeners.SingleOrDefault(o => o.ClipboardEvent.Purpose == Purpose);

            if (clipboardEventListenerWindow == null)
            {
                ClipboardEvent clipboardEvent = new ClipboardEvent() { Purpose = Purpose, OnClipboardDraw = OnClipboardDraw };
                ClipboardEventListenerWindow window = new ClipboardEventListenerWindow(clipboardEvent);
                IntPtr windowHandle = window.Handle;
                bool issuccess = WinApiMethods.AddClipboardFormatListener(windowHandle);
                if (!issuccess)
                {
                    Win32Exception ex = new Win32Exception(Marshal.GetLastWin32Error());

                    throw ex;

                }
                else
                {
                    RegisteredClipboardEventListeners.Add(clipboardEventListenerWindow);
                }
            }
            else
            {
                throw new AlreadyMappedException(clipboardEventListenerWindow.ClipboardEvent);
            }
        }
Beispiel #3
0
        public void UnRegisterHotKey(string Purpose)
        {
            HotKey key = RegisteredHotKeys.SingleOrDefault(o => o.Purpose == Purpose);

            if (key != null)
            {
                bool issuccess = WinApiMethods.UnregisterHotKey(this.windowHandle, key.id);
                if (!issuccess)
                {
                    Win32Exception ex = new Win32Exception(Marshal.GetLastWin32Error());

                    throw ex;
                }
                else
                {
                    RegisteredHotKeys.Remove(key);
                }
            }
            else
            {
                throw new KeyNotFoundException(Purpose);
            }
        }
Beispiel #4
0
        public void ReplaceHotKey(string Purpose, KeyModifiers modifiers, Keys vk, Action <HotKey> OnPressed)
        {
            HotKey key = RegisteredHotKeys.SingleOrDefault(o => o.Purpose == Purpose);

            if (key != null)
            {
                key.fsModifiers = modifiers;
                key.vk          = vk;
                bool issuccess = WinApiMethods.RegisterHotKey(windowHandle, key.id, key.fsModifiers, (uint)key.vk);
                if (!issuccess)
                {
                    key = null;
                    Win32Exception ex = new Win32Exception(Marshal.GetLastWin32Error());
                    if (ex.Message == "Hot key is already registered")
                    {
                        throw ex;
                    }
                }
            }
            else
            {
                throw new KeyNotFoundException(Purpose);
            }
        }
        public void UnRegisterClipboardEvent(string Purpose)
        {
            ClipboardEventListenerWindow clipboardEventListenerWindow = RegisteredClipboardEventListeners.SingleOrDefault(o => o.ClipboardEvent.Purpose == Purpose);

            if (clipboardEventListenerWindow != null)
            {
                bool issuccess = WinApiMethods.RemoveClipboardFormatListener(clipboardEventListenerWindow.Handle);
                if (!issuccess)
                {
                    Win32Exception ex = new Win32Exception(Marshal.GetLastWin32Error());

                    throw ex;

                }
                else
                {
                    RegisteredClipboardEventListeners.Remove(clipboardEventListenerWindow);
                }
            }
            else
            {
                throw new ClipboardEventNotFoundException(Purpose);
            }
        }
Beispiel #6
0
 public void DisableDisplayCapture(IntPtr handle)
 {
     WinApiMethods.SetWindowDisplayAffinity(handle, 1);
 }