Ejemplo n.º 1
0
        public void RegisterHotkey(HotkeyInfo hotkeyInfo)
        {
            if (hotkeyInfo != null && hotkeyInfo.Status != HotkeyStatus.Registered)
            {
                if (!hotkeyInfo.IsValidHotkey)
                {
                    hotkeyInfo.Status = HotkeyStatus.NotConfigured;
                    return;
                }

                if (hotkeyInfo.ID == 0)
                {
                    string uniqueID = Helpers.GetUniqueID();
                    hotkeyInfo.ID = NativeMethods.GlobalAddAtom(uniqueID);

                    if (hotkeyInfo.ID == 0)
                    {
                        DebugHelper.WriteLine("Unable to generate unique hotkey ID: " + hotkeyInfo);
                        hotkeyInfo.Status = HotkeyStatus.Failed;
                        return;
                    }
                }

                if (!NativeMethods.RegisterHotKey(Handle, hotkeyInfo.ID, (uint)hotkeyInfo.ModifiersEnum, (uint)hotkeyInfo.KeyCode))
                {
                    NativeMethods.GlobalDeleteAtom(hotkeyInfo.ID);
                    DebugHelper.WriteLine("Unable to register hotkey: " + hotkeyInfo);
                    hotkeyInfo.ID = 0;
                    hotkeyInfo.Status = HotkeyStatus.Failed;
                    return;
                }

                hotkeyInfo.Status = HotkeyStatus.Registered;
            }
        }
Ejemplo n.º 2
0
 private void HotkeyProc(HotkeyInfo hotkeyInfo)
 {
     logTextBox.Text += string.Format("{0} : Hotkey Proc! {1}, {2}{3}", DateTime.Now.ToString("hh:MM:ss.fff"),
                                      hotkeyInfo.Key, hotkeyInfo.Modifiers, Environment.NewLine);
     logTextBox.Select(logTextBox.Text.Length, 0);
     logTextBox.ScrollToCaret();
 }
Ejemplo n.º 3
0
 public HotkeySettings(HotkeyType job, Keys hotkey = Keys.None)
     : this()
 {
     TaskSettings = TaskSettings.GetDefaultTaskSettings();
     TaskSettings.Job = job;
     TaskSettings.Description = job.GetDescription();
     HotkeyInfo = new HotkeyInfo { Hotkey = hotkey };
 }
Ejemplo n.º 4
0
        public HotkeyInfo RegisterHotkey(HotkeyInfo hotkeyInfo)
        {
            if (hotkeyInfo != null && hotkeyInfo.Status != HotkeyStatus.Registered)
            {
                if (hotkeyInfo.ID > 0)
                {
                    return RegisterHotkey(hotkeyInfo.Hotkey, hotkeyInfo.HotkeyPress, hotkeyInfo.ID);
                }
                else
                {
                    return RegisterHotkey(hotkeyInfo.Hotkey, hotkeyInfo.HotkeyPress);
                }
            }

            return hotkeyInfo;
        }
Ejemplo n.º 5
0
 private void HotkeyProc(HotkeyInfo hotkeyInfo)
 {
     Console.WriteLine("{0} : Hotkey Proc! {1}, {2}{3}", DateTime.Now.ToString("hh:MM:ss.fff"),
                       hotkeyInfo.Key, hotkeyInfo.Modifiers, Environment.NewLine);
     if (hotkeyInfo.Key == Keys.F5)
     {
         rebuildGroups();
     }
     else
     {
         foreach (ProgramGroup group in Program.PGM.programGroups)
         {
             group.isThisYourKotkey(hotkeyInfo);
         }
     }
     updateDisplayedVolume();
 }
Ejemplo n.º 6
0
        public void RegisterHotkey(Hotkey hotkey, Action <Hotkey> action)
        {
            if (action == null)
            {
                throw new ArgumentNullException(nameof(action));
            }
            if (registeredHotkeys.ContainsKey(hotkey))
            {
                return;
            }

            HotkeyInfo hi = new HotkeyInfo();

            hi.Hotkey       = hotkey;
            hi.Action       = action;
            hi.WindowHandle = IntPtr.Zero;

            string uniqueID = Guid.NewGuid().ToString("N");

            hi.ID = NativeMethods.GlobalAddAtom(uniqueID);

            if (hi.ID == 0)
            {
                throw new Exception($"Failed to create unique ID for hotkey {hotkey}", new Win32Exception(Marshal.GetLastWin32Error()));
            }

            var modifiers = ModifiersFromHotkey(hi.Hotkey);
            var keycode   = hi.Hotkey.KeyCode & Keys.KeyCode;

            if (NativeMethods.RegisterHotKey(hi.WindowHandle, hi.ID, modifiers, (uint)keycode))
            {
                registeredHotkeys.Add(hotkey, hi);
            }
            else
            {
                int error = Marshal.GetLastWin32Error();

                // Cleanup atom
                NativeMethods.GlobalDeleteAtom(hi.ID);
                hi.ID = 0;

                throw new Exception($"Failed to register hotkey {hotkey}", new Win32Exception(error));
            }
        }
Ejemplo n.º 7
0
        public override bool Equals(System.Object obj)
        {
            // If parameter is null return false.
            if (obj == null)
            {
                return(false);
            }

            // If parameter cannot be cast to Point return false.
            HotkeyInfo p = obj as HotkeyInfo;

            if ((System.Object)p == null)
            {
                return(false);
            }

            // Return true if the fields match:
            return((modifier == p.Modifiers) && (key == p.Key));
        }
Ejemplo n.º 8
0
        public void SetHotkeyInfo(HotkeyInfo hotkey)
        {
            this.Hotkey = hotkey.keyCode;

            if (hotkey.shift)
            {
                this.HotkeyModifiers = this.HotkeyModifiers | Keys.Shift;
            }

            if (hotkey.alt)
            {
                this.HotkeyModifiers = this.HotkeyModifiers | Keys.Alt;
            }

            if (hotkey.control)
            {
                this.HotkeyModifiers = this.HotkeyModifiers | Keys.Control;
            }
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Catches Windows' message about pressed hotkey
        /// and fires up the HandleHotkey method
        /// </summary>
        /// <param name="m"></param>
        protected override void WndProc(ref Message m)
        {
            // we check if the message is about out hotkey
            var hotkeyInfo = HotkeyInfo.GetFromMessage(m);

            if (hotkeyInfo != null)
            {
                string command = null;
                foreach (GlobalHotkey gh in this.ghList)
                {
                    if (gh.Key.Equals((int)hotkeyInfo.Key))
                    {
                        command = gh.command;
                    }
                }
                this.HandleHotkey(hotkeyInfo, command);
            }

            base.WndProc(ref m);
        }
Ejemplo n.º 10
0
        /*
         *  This function is called with info on what hotkey was pressed,
         *  if the hotkey that was pressed belongs to this group then it
         *  performs the appropriate task
         */
        public void isThisYourKotkey(HotkeyInfo hotkeyInfo)
        {
            if (!hasHotkey)
            {
                return;
            }
            if (hotkeyInfo.Key == (Keys)hotkeyVolUp.Key &&
                hotkeyInfo.Modifiers == (Modifiers)hotkeyVolUp.Modifier)
            {
                //volAsPercent += 5;
                setVolume(volAsPercent + 5);
            }

            if (hotkeyInfo.Key == (Keys)hotkeyVolDown.Key &&
                hotkeyInfo.Modifiers == (Modifiers)hotkeyVolDown.Modifier)
            {
                //volAsPercent -= 5;
                setVolume(volAsPercent - 5);
            }
            updateVolume();
        }
Ejemplo n.º 11
0
        public bool UnregisterHotkey(HotkeyInfo hotkeyInfo)
        {
            if (hotkeyInfo != null)
            {
                if (hotkeyInfo.ID > 0)
                {
                    bool result = NativeMethods.UnregisterHotKey(Handle, hotkeyInfo.ID);

                    if (result)
                    {
                        NativeMethods.GlobalDeleteAtom(hotkeyInfo.ID);
                        hotkeyInfo.ID = 0;
                        hotkeyInfo.Status = HotkeyStatus.NotConfigured;
                        return true;
                    }
                }

                hotkeyInfo.Status = HotkeyStatus.Failed;
            }

            return false;
        }
Ejemplo n.º 12
0
        /*
         * private void KeybindingPrompt_KeyPress(object sender, KeyPressEventArgs e)
         * {
         *  Console.WriteLine("A KEY WAS PRESSED!!!!! :   "+ e.KeyChar+ " string: "+ e.ToString() );
         *  //this.Dispose();
         * }*/

        protected override void WndProc(ref Message m)
        {
            Console.WriteLine("something happened!");
            if (m.Msg == 0x101)
            {
                m.LParam = (IntPtr)((int)m.WParam * (int)Math.Pow(16, 4));
                Console.WriteLine(m.WParam);
                Console.WriteLine(m.LParam);
                m.Msg = Win32.WM_HOTKEY_MSG_ID;
            }
            var hotkeyInfo = HotkeyInfo.GetFromMessage(m);

            if (m.Msg == 0x101 || m.Msg == Win32.WM_HOTKEY_MSG_ID)
            {
                Console.WriteLine(m.ToString());
                Console.WriteLine("Detected!");
            }
            if (hotkeyInfo != null)
            {
                HotkeyProc(hotkeyInfo);
            }
            base.WndProc(ref m);
        }
Ejemplo n.º 13
0
        public static bool loadConfig(string module, Expandable.IConfig config, Hotkey[] hks)
        {
            string file = module == CORE_ID ? CORE_CONFIG_PATH : CONFIG_PATH + module + ".ini";

            if (!File.Exists(file))
            {
                return(false);
            }

            Config tmp = new Config();

            using (Stream str = File.OpenRead(file))
            {
                try
                {
                    XmlSerializer xs = new XmlSerializer(typeof(Config));
                    tmp = (Config)xs.Deserialize(str);
                }
                catch (Exception e)
                {
                    MessageBox.Show(e.Message);
                }
            }

            if (tmp.Properties.Count == 0 && tmp.Hotkeys.Count == 0)
            {
                return(false);
            }

            if (tmp.Hotkeys.Count > 0)
            {
                for (int i = 0; i < hks.Length; i++)
                {
                    HotkeyInfo hki = tmp.Hotkeys.FirstOrDefault(_ => _.id == hks[i].id);
                    if (hki.id != null)
                    {
                        hks[i].keys = hki.keys;
                    }
                }
            }

            if (tmp.Properties.Count > 0)
            {
                Type        confType = config.GetType();
                FieldInfo[] fields   = confType.GetFields();
                foreach (FieldInfo fi in fields)
                {
                    object value = tmp.Properties.FirstOrDefault(_ => _.name == fi.Name).value;
                    if (value == null)
                    {
                        continue;
                    }

                    if (value.GetType().AssemblyQualifiedName == fi.FieldType.AssemblyQualifiedName)
                    {
                        fi.SetValue(config, value);
                    }
                }
            }

            return(true);
        }
Ejemplo n.º 14
0
 public HotkeyEventArgs(Hotkey hotkey, HotkeyInfo info)
 {
     HotkeyInfo = info;
     Hotkey = hotkey;
 }
Ejemplo n.º 15
0
 public HotkeySettings(HotkeyType job, Keys hotkey = Keys.None) : this()
 {
     TaskSettings = TaskSettings.GetDefaultTaskSettings();
     TaskSettings.Job = job;
     HotkeyInfo = new HotkeyInfo(hotkey);
 }
Ejemplo n.º 16
0
        public bool UnregisterHotkey(HotkeyInfo hotkeyInfo)
        {
            if (hotkeyInfo != null)
            {
                bool result = UnregisterHotkey(hotkeyInfo.ID);

                if (result)
                {
                    hotkeyInfo.Status = HotkeyStatus.NotConfigured;
                }
                else
                {
                    hotkeyInfo.Status = HotkeyStatus.Failed;
                }

                HotkeyList.Remove(hotkeyInfo);
                return result;
            }

            return false;
        }
Ejemplo n.º 17
0
 public void UpdateHotkey(HotkeyInfo hotkeyInfo)
 {
     HotkeyInfo = hotkeyInfo;
     UpdateHotkeyText();
 }
Ejemplo n.º 18
0
 public HotkeySettings()
 {
     HotkeyInfo = new HotkeyInfo();
 }
Ejemplo n.º 19
0
 public HotkeyInfo UpdateHotkey(HotkeyInfo hotkeyInfo)
 {
     UnregisterHotkey(hotkeyInfo);
     return RegisterHotkey(hotkeyInfo);
 }
Ejemplo n.º 20
0
 public void Reset()
 {
     EditingHotkey = false;
     HotkeyInfo = new HotkeyInfo();
     SetDefaultButtonText();
 }
Ejemplo n.º 21
0
        private HotkeyInfo RegisterHotkey(Keys hotkey, Action hotkeyPress, ushort id)
        {
            HotkeyInfo hotkeyInfo = new HotkeyInfo(hotkey, hotkeyPress, id);

            if (!hotkeyInfo.IsValidHotkey)
            {
                hotkeyInfo.Status = HotkeyStatus.NotConfigured;
                return hotkeyInfo;
            }

            if (id == 0)
            {
                DebugHelper.WriteLine("Unable to generate unique hotkey ID: " + hotkeyInfo);
                hotkeyInfo.Status = HotkeyStatus.Failed;
                return hotkeyInfo;
            }

            if (IsHotkeyExist(hotkey))
            {
                DebugHelper.WriteLine("Hotkey already exist: " + hotkeyInfo);
                hotkeyInfo.Status = HotkeyStatus.Failed;
                return hotkeyInfo;
            }

            if (!NativeMethods.RegisterHotKey(Handle, (int)id, (uint)hotkeyInfo.ModifiersEnum, (uint)hotkeyInfo.KeyCode))
            {
                NativeMethods.GlobalDeleteAtom(id);
                DebugHelper.WriteLine("Unable to register hotkey: " + hotkeyInfo);
                hotkeyInfo.Status = HotkeyStatus.Failed;
                return hotkeyInfo;
            }

            HotkeyList.Add(hotkeyInfo);

            hotkeyInfo.Status = HotkeyStatus.Registered;
            return hotkeyInfo;
        }
Ejemplo n.º 22
0
 public HotkeyEventArgs(Hotkey hotkey, HotkeyInfo info)
 {
     HotkeyInfo = info;
     Hotkey     = hotkey;
 }
Ejemplo n.º 23
0
 private void UpdateHotkeyText()
 {
     Text = HotkeyInfo.ToString();
     Invalidate();
 }
Ejemplo n.º 24
0
 public HotkeySettings(CaptureType job, Keys hotkey = Keys.None)
     : this()
 {
     Job = job;
     HotkeyInfo = new HotkeyInfo(hotkey);
 }
Ejemplo n.º 25
0
 public void Reset()
 {
     EditingHotkey = false;
     HotkeyInfo    = new HotkeyInfo();
     SetDefaultButtonText();
 }
Ejemplo n.º 26
0
 public void UpdateHotkey(HotkeyInfo hotkeyInfo)
 {
     HotkeyInfo = hotkeyInfo;
     UpdateHotkeyText();
 }
 private void LoadDefaults()
 {
     PersonnalFolder = DefaultPersonnalFolder;
     AreaHotkey      = DefaultAreaHotkey;
     ClipboardHotkey = DefaultClipboardHotkey;
 }
Ejemplo n.º 28
0
 private void HotkeyProc(HotkeyInfo hotkeyInfo)
 {
     Native.SetMonitorEnable(this.Handle, true);
     Application.Exit();
 }
Ejemplo n.º 29
0
 public HotkeySettings()
 {
     HotkeyInfo = new HotkeyInfo();
     Job = CaptureType.None;
 }