MovablePython.Hotkey.Register C# (CSharp) Method

Register() public method

public Register ( Control windowControl ) : bool
windowControl Control
return bool
        public bool Register(Control 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.Handle, 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;
        }

Usage Example

Esempio n. 1
0
        public GBGMain()
        {
            InitializeComponent();
            ttUpdater.Interval = 500;
            ttUpdater.Tick += new EventHandler((o, e) =>
            {
                long mil = totalRunTime.ElapsedMilliseconds,
                     seconds = mil / 1000,
                     minutes = seconds / 60 % 60,
                     hours = minutes / 60,
                     days = hours / 24;

                lblTotalRunTime.Text = "Approx. " + days + "d " + (hours % 24) + "h " + (minutes % 60) + "m " + (seconds % 60) + "s";
            });

            bgw.WorkerSupportsCancellation = true;
            bgw.WorkerReportsProgress = true;
            bgw.DoWork += new DoWorkEventHandler(RunBot_Work);
            bgw.ProgressChanged += new ProgressChangedEventHandler(bgw_ProgressChanged);
            bgw.RunWorkerCompleted += new RunWorkerCompletedEventHandler(bgw_RunWorkerCompleted);

            Hotkey hkRunBot = new Hotkey(Keys.F12, false, true, true, false);

            hkRunBot.Pressed += delegate
            {
                if(btnStopBot.Enabled)
                    StopBot();
                else if(btnRunBot.Enabled)
                    RunBot();
            };

            hkRunBot.Register(this);
        }
All Usage Examples Of MovablePython.Hotkey::Register