Ejemplo n.º 1
0
        /// <summary>
        /// Register a new global hot key. This will throw an exception if the hot
        /// key is already registered.
        /// </summary>
        /// <param name="modifiedKey">The modified key.</param>
        /// <param name="HotKeyCallback">A callback that will be invoked when the HotKey is pressed.</param>
        public void Register(ModifiedKey modifiedKey, HotKeyCallback hotKeyCallback)
        {
            modifiedKey.ThrowIfNull("modifiedKey");

            hotKeyCallback.ThrowIfNull("hotKeyCallback");
            Register(modifiedKey.Modifiers, modifiedKey.Key, hotKeyCallback);
        }
Ejemplo n.º 2
0
        void AutoTemplateCallback(ModifiedKey key)
        {
            var    template     = AutoTemplates.Single(t => t.ModifiedKey == key);
            string replacedText = template.Process();

            TOUT.WaitForModifiersUp();
            TOUT.PasteString(replacedText);
        }
Ejemplo n.º 3
0
        void OutputHeaderComment(ModifiedKey key)
        {
            string text = HeaderCommentTemplate.Process();

            TOUT.WaitForModifiersUp();
            TOUT.PasteString(text).
            Move(-9, 3).
            SelectToEndOfLine();
        }
Ejemplo n.º 4
0
        void HandleHotKey(ModifiedKey HotKeyInfo)
        {
            var handler = HotKeyPressed;

            if (handler != null)
            {
                var args = new HotKeyPressedEventArgs(HotKeyInfo);
                handler(this, args);
            }
        }
Ejemplo n.º 5
0
        protected override void WndProc(ref Message m)
        {
            var HotKeyInfo = ModifiedKey.GetFromMessage(m);

            if (HotKeyInfo != null)
            {
                HandleHotKey(HotKeyInfo);
            }
            base.WndProc(ref m);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Create a new <code>Template</code> object.
        /// </summary>
        /// <param name="key">The modified key that the template will be invoked by.</param>
        /// <param name="name">Name of the template. Keep this short.</param>
        /// <param name="description">Description of the template. More descriptive than the name.</param>
        /// <param name="filePath">The full path of the file that the template was loaded from.</param>
        /// <param name="originalText">The text of the template.</param>
        public TextTemplate(ModifiedKey key, string name, string description, string filePath, string originalText)
        {
            originalText.ThrowIfNull("originalText", "You must specify the text for the template.");

            ModifiedKey  = key;
            Name         = name;
            Description  = description;
            FilePath     = filePath;
            OriginalText = originalText;
        }
Ejemplo n.º 7
0
        void ShowMainForm(ModifiedKey key)
        {
            // Ensure form only shown once.
            if (MainForm != null)
            {
                return;
            }

            using (var f = new MainForm())
            {
                MainForm        = f;
                f.AutoTemplates = AutoTemplates;
                f.ShowDialog();
                MainForm = null;
            }
        }
Ejemplo n.º 8
0
        static void MyCallback(ModifiedKey HotKeyInfo)
        {
            // Slow
            //TO.WaitForModifiersUp();
            //TO.PasteLine("Hello world1");
            //TO.PasteLine("Hello world2");
            //TO.PasteLine("Hello world3");
            //TO.Move(2, 0);
            //TO.SelectNextWord();

            // Quick because of one paste.
            // Alsow shows fluent chaining syntax.
            TO.WaitForModifiersUp().
            PasteLine("Hello world1\r\nHello world2\r\nHello world3").
            Move(-2, 0).
            SelectNextWord();
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Unregisters a single global hot key.
        /// </summary>
        /// <param name="modifiers">Key modifiers (Shift, Alt etc.) that you want applied.</param>
        /// <param name="key">The key.</param>
        public void Unregister(Modifiers modifiers, Keys key)
        {
            modifiers.ThrowIfNull("modifiers");
            key.ThrowIfNull("key");

            log.Debug("UnregisterGlobalHotKey, Hot key = " + ModifiedKey.ToString(modifiers, key));

            // For multi-threaded apps, we need to be careful to use the form's handle
            // on the same thread as it was initially created.
            if (MessageLoopForm.InvokeRequired)
            {
                MessageLoopForm.Invoke(new MethodInvoker(delegate { InternalUnregister(modifiers, key); }));
            }
            else
            {
                InternalUnregister(modifiers, key);
            }

            log.Debug("Hot key successfully unregistered");
        }
Ejemplo n.º 10
0
        /// <summary>
        /// 修飾キーを取得する
        /// </summary>
        /// <param name="modifierKey"></param>
        /// <returns></returns>
        public static Keys GetModifiedKeys(ModifiedKey modifierKey)
        {
            Keys keys = Keys.None;

            if ((ModifiedKey.Alt & modifierKey) == ModifiedKey.Alt)
            {
                keys |= Keys.Alt;
            }

            if ((ModifiedKey.Shift & modifierKey) == ModifiedKey.Shift)
            {
                keys |= Keys.ShiftKey;
            }

            if ((ModifiedKey.Ctrl & modifierKey) == ModifiedKey.Ctrl)
            {
                keys |= Keys.ControlKey;
            }

            return(keys);
        }
Ejemplo n.º 11
0
        static TemplateConfig ParseTemplateConfig(string templateFilePath, string azConfig)
        {
            var    ini    = new IniParser(azConfig, true);
            string hotKey = ini.GetValue("Config", "Key");

            ModifiedKey modifiedKey = null;

            if (!String.IsNullOrWhiteSpace(hotKey))
            {
                if (!ModifiedKey.TryParse(hotKey, out modifiedKey))
                {
                    var msg = String.Format(CultureInfo.InvariantCulture, "The modified key specification {0} in template {1} is invalid.", hotKey, templateFilePath);
                    throw new TemplateFormatException(msg);
                }
            }

            var result = new TemplateConfig();

            result.Key         = modifiedKey;
            result.Name        = ini.GetValue("Config", "Name");
            result.Description = ini.GetValue("Config", "Description");

            return(result);
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Unregisters a single global hot key.
        /// </summary>
        /// <param name="modifiedKey">The <code>ModifiedKey</code> to unregister.</param>
        public void Unregister(ModifiedKey modifiedKey)
        {
            modifiedKey.ThrowIfNull("key");

            Unregister(modifiedKey.Modifiers, modifiedKey.Key);
        }
Ejemplo n.º 13
0
 /// <summary>
 /// Construct a new <code>HotKeyPressedEventArgs</code> object.
 /// </summary>
 /// <param name="modifiedKey">The <code>ModifiedKey</code> that was pressed.</param>
 public HotKeyPressedEventArgs(ModifiedKey modifiedKey)
 {
     ModifiedKey = modifiedKey;
 }
Ejemplo n.º 14
0
 /// <summary>
 /// Create a new <code>Template</code> object.
 /// </summary>
 /// <param name="key">The modified key that the template will be invoked by.</param>
 /// <param name="originalText">The text of the template.</param>
 public TextTemplate(ModifiedKey key, string originalText)
     : this(key, null, null, null, originalText)
 {
 }
Ejemplo n.º 15
0
 public void TestResolve()
 {
     Keys k1 = ModifiedKey.ConvertCharactorToKey('a');
     Keys k2 = ModifiedKey.ConvertCharactorToKey(';');
     Keys k3 = ModifiedKey.ConvertCharactorToKey('5');
 }