GetCanRegister() public method

public GetCanRegister ( Control windowControl ) : bool
windowControl Control
return bool
Exemplo n.º 1
0
        internal SUApplicationContext()
        {
            // только создаем форму, она все равно нужна
            // чтобы слушать хоткеи
            form = new Form();

            // создаем и регистрируем глобайльный хоткей
            hk = new Hotkey(Keys.A, false, false, false, true);
            hk.Pressed += delegate { SendSwitchCommand(); };
            if (hk.GetCanRegister(form))
            hk.Register(form);

            // Вешаем событие на выход
            Application.ApplicationExit += Application_ApplicationExit;
        }
Exemplo n.º 2
0
        private void RegisterHotKey()
        {
            // Enable alt + space hotkey.
            // This should be an option in future versions.
            var hk = new Hotkey();
            hk.Alt = true;
            hk.KeyCode = Keys.Space;
            hk.Pressed += HotKey_Pressed;

            if (hk.GetCanRegister(this))
            {
                hk.Register(this);
            }
            else
            {
                Debug.WriteLine("Could not register hotkey.");
            }
        }
Exemplo n.º 3
0
        private void applyShortcutButton_Click(object sender, EventArgs e)
        {
            try
            {
                int notMetaCount = shortcutKeys.Count(k => !IsMetaKey(k));
                if (notMetaCount == 0)
                {
                    ShowErrorMessage("You should also choose one character that is not CTRL, SHIFT, ALT or WIN");
                    return;
                }

                bool ctrl = false;
                bool shift = false;
                bool alt = false;
                bool win = false;
                Keys key = Keys.F19;

                foreach (Keys item in shortcutKeys)
                {
                    if (item == Keys.ControlKey)
                    {
                        ctrl = true;
                    }
                    else if (item == Keys.ShiftKey)
                    {
                        shift = true;
                    }
                    else if (item == Keys.LWin || item == Keys.RWin)
                    {
                        win = true;
                    }
                    else if (item == Keys.Alt || item == Keys.Menu)
                    {
                        alt = true;
                    }
                    else
                    {
                        key = item;
                    }
                }

                if (hotKey != null && hotKey.Registered)
                {
                    hotKey.Unregister();
                }

                hotKey = new Hotkey(key, shift, ctrl, alt, win);
                hotKey.Pressed += (hkSender, hkArgs) => ShowScreenShotForm();

                if (hotKey.GetCanRegister(shortcut))
                {
                    hotKey.Register(shortcut);
                    new UserSettings().Shortcut = shortcutKeys;
                }
                else
                {
                    MessageBox.Show(this, "There is another application using this combination already. Please choose another one",
                        "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
            }
            catch (Exception ex)
            {
                ShowErrorMessage(ex.Message);
            }
        }
Exemplo n.º 4
0
        static void Main()
        {
            AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;

            if (!mutexCreated)
            {
                if (MessageBox.Show(
                  "JediConcentrate2 is already running. Hotkeys cannot be shared between different instances. Are you sure you wish to run this second instance?",
                  "JediConcentrate2 already running",
                  MessageBoxButtons.YesNo,
                  MessageBoxIcon.Question) != DialogResult.Yes)
                {
                    mutex.Close();
                    return;
                }
            }

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            frm = new frmJedi();
            frm.Show();
            frm.Hide();

            ContextMenu menu = new ContextMenu();
            menu.MenuItems.Add(new MenuItem("About"));
            menu.MenuItems.Add(new MenuItem("Exit"));
            menu.MenuItems[0].Click += About_Click;
            menu.MenuItems[1].Click += Exit_Click;
            menu.Popup += Menu_Popup;

            icon = new NotifyIcon() { Icon = Properties.Resources.yoda, Visible = true, ContextMenu = menu };

            hk = new Hotkey();
            hk.KeyCode = Keys.J;
            hk.Windows = true;
            hk.Pressed += delegate { ToggleConcentrate(); };

            if (hk.GetCanRegister(frm)) { hk.Register(frm); }

            thPoll = new Thread(new ThreadStart(Poll));
            thPoll.Start();

            Application.Run();
        }
Exemplo n.º 5
0
        // Register hotkeys
        private void RegisterHotKeys()
        {
            Object s = null;
            EventArgs e = null;

            playhotkey = new Hotkey();
            playhotkey.Alt = true;
            playhotkey.KeyCode = Keys.P;
            playhotkey.Pressed += delegate { btnPlay_Click(s, e); };

            prevhotkey = new Hotkey();
            prevhotkey.Alt = true;
            prevhotkey.KeyCode = Keys.Left;
            prevhotkey.Pressed += delegate { btnPrev_Click(s, e); };

            nexthotkey = new Hotkey();
            nexthotkey.Alt = true;
            nexthotkey.KeyCode = Keys.Right;
            nexthotkey.Pressed += delegate { btnNext_Click(s, e); };

            stophotkey = new Hotkey();
            stophotkey.Alt = true;
            stophotkey.KeyCode = Keys.S;
            stophotkey.Pressed += delegate { btnStop_Click(s, e); };

            hidehotkey = new Hotkey();
            hidehotkey.Alt = true;
            hidehotkey.KeyCode = Keys.H;
            hidehotkey.Pressed += delegate { HideMe(); };

            try
            {
                if (!playhotkey.GetCanRegister(this))
                {
                    MessageBox.Show("Failed to register hotkey!\nPlay");
                }
                else
                {
                    playhotkey.Register(this);
                }

                if (!prevhotkey.GetCanRegister(this))
                {
                    MessageBox.Show("Failed to register hotkey!\nPrev");
                }
                else
                {
                    prevhotkey.Register(this);
                }

                if (!nexthotkey.GetCanRegister(this))
                {
                    MessageBox.Show("Failed to register hotkey!\nNext");
                }
                else
                {
                    nexthotkey.Register(this);
                }

                if (!stophotkey.GetCanRegister(this))
                {
                    MessageBox.Show("Failed to register hotkey!\nStop");
                }
                else
                {
                    stophotkey.Register(this);
                }

                if (!hidehotkey.GetCanRegister(this))
                {
                    MessageBox.Show("Failed to register hotkey!\nHide");
                }
                else
                {
                    hidehotkey.Register(this);
                }
            }
            catch { }
        }