/// <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); }
void AutoTemplateCallback(ModifiedKey key) { var template = AutoTemplates.Single(t => t.ModifiedKey == key); string replacedText = template.Process(); TOUT.WaitForModifiersUp(); TOUT.PasteString(replacedText); }
void OutputHeaderComment(ModifiedKey key) { string text = HeaderCommentTemplate.Process(); TOUT.WaitForModifiersUp(); TOUT.PasteString(text). Move(-9, 3). SelectToEndOfLine(); }
void HandleHotKey(ModifiedKey HotKeyInfo) { var handler = HotKeyPressed; if (handler != null) { var args = new HotKeyPressedEventArgs(HotKeyInfo); handler(this, args); } }
protected override void WndProc(ref Message m) { var HotKeyInfo = ModifiedKey.GetFromMessage(m); if (HotKeyInfo != null) { HandleHotKey(HotKeyInfo); } base.WndProc(ref m); }
/// <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; }
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; } }
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(); }
/// <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"); }
/// <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); }
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); }
/// <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); }
/// <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; }
/// <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) { }
public void TestResolve() { Keys k1 = ModifiedKey.ConvertCharactorToKey('a'); Keys k2 = ModifiedKey.ConvertCharactorToKey(';'); Keys k3 = ModifiedKey.ConvertCharactorToKey('5'); }