MovablePython.Hotkey.RegisterHotKey C# (CSharp) Method

RegisterHotKey() private method

private RegisterHotKey ( IntPtr hWnd, int id, uint fsModifiers, Keys vk ) : int
hWnd System.IntPtr
id int
fsModifiers uint
vk Keys
return int
        private static extern int RegisterHotKey(IntPtr hWnd, int id, uint fsModifiers, Keys vk);

Usage Example

Esempio n. 1
0
        public bool Register(IntPtr windowControl)
        {
            // Check that we have not registered
            if (this.registered)
            {
                throw new NotSupportedException("You cannot register a hotkey that is already registered");
            }

            // We can't register an empty hotkey
            if (this.Empty)
            {
                throw new NotSupportedException("You cannot register an empty hotkey");
            }

            // Get an ID for the hotkey and increase current ID
            this.id          = Hotkey.currentID;
            Hotkey.currentID = Hotkey.currentID + 1 % Hotkey.maximumID;

            // Translate modifier keys into unmanaged version
            uint modifiers = (this.Alt ? Hotkey.MOD_ALT : 0) | (this.Control ? Hotkey.MOD_CONTROL : 0) |
                             (this.Shift ? Hotkey.MOD_SHIFT : 0) | (this.Windows ? Hotkey.MOD_WIN : 0);

            // Register the hotkey
            if (Hotkey.RegisterHotKey(windowControl, this.id, modifiers, keyCode) == 0)
            {
                // Is the error that the hotkey is registered?
                if (Marshal.GetLastWin32Error() == ERROR_HOTKEY_ALREADY_REGISTERED)
                {
                    return(false);
                }
                else
                {
                    throw new Win32Exception();
                }
            }

            // Save the control reference and register state
            this.registered = true;
            //this.windowControl = windowControl;

            // We successfully registered
            return(true);
        }