/// <summary> /// Registers the system-wide hot key. /// </summary> /// <param name="key">The key.</param> /// <param name="modifiers">The key modifiers.</param> /// <returns>The registered <see cref="HotKeyInfo"/>.</returns> public HotKeyInfo Register(Key key, ModifierKeys modifiers) { var hotKey = new HotKeyInfo(key, modifiers); Register(hotKey); return(hotKey); }
// ショートカットキーの設定 private void ListViewShortcut_KeyUp(object sender, KeyEventArgs e) { if (ListViewShortcut.SelectedItems.Count <= 0) { return; } if (e.KeyCode == Keys.Enter) { if (IsEntered) { IsEntered = false; } else { ListViewHitInfo = ListViewShortcut.HitTest(ListViewShortcut.SelectedItems[0].Position); if (ListViewHitInfo.SubItem != null) { Dll.SetKeyboardHook(true); HotKey = new HotKeyInfo(); ListViewInput = new ListViewInputBox(ListViewShortcut, ListViewHitInfo.Item, 1); ListViewInput.FinishInput += new ListViewInputBox.InputEventHandler(Input_FinishInput); ListViewInput.Disposed += new EventHandler(Input_Disposed); ListViewInput.Show(); } } } else if (e.KeyCode == Keys.Delete) { ListViewShortcut.SelectedItems[0].SubItems[1].Text = ""; GHManager.TempSettings.Hotkey.HotKeys[(int)ListViewShortcut.SelectedItems[0].Tag].SetKeys(0, 0); } }
/// <summary> /// Set global hotkey /// </summary> private void SetShortcutKey(ClipboardInfo selectedInfo) { try { ClipboardInfoList clipboardInfoList = this.GetClipboardInfoList; HotKeyInfo hkInfo = new HotKeyInfo(); if (selectedInfo != null) { string hotkey = selectedInfo.SHORTKEY; string hotkeyNum = hotkey.Substring(hotkey.LastIndexOf("+") + 1); bool ctrl = hotkey.Contains("Ctrl"); bool alt = hotkey.Contains("Alt"); bool shift = hotkey.Contains("Shift"); // setting global hotKey Keys key = Keys.None; switch (hotkeyNum) { case "1": key = Keys.D1; break; case "2": key = Keys.D2; break; case "3": key = Keys.D3; break; case "4": key = Keys.D4; break; case "5": key = Keys.D5; break; case "6": key = Keys.D6; break; case "7": key = Keys.D7; break; case "8": key = Keys.D8; break; case "9": key = Keys.D9; break; case "0": key = Keys.D0; break; default: break; } Hotkey hk = this.SetHotKey(key, shift, ctrl, alt, false, selectedInfo); if (hk == null) { return; } hkInfo.HOTKEY = hk; hkInfo.HOTKEYNAME = hotkey; hotKeyInfoList.Add(hkInfo); } } catch (Exception ex) { ConsoleLib.ConsoleLib.WriteFormatted(ex.ToString() + " ", t); ConsoleLib.ConsoleLib.WriteLine(Environment.NewLine); } }
/// <summary> /// Unregisters previously registered hot key. /// </summary> /// <param name="hotKey">The registered hot key.</param> public void Unregister(HotKeyInfo hotKey) { if (registered.TryGetValue(hotKey, out int id)) { WinApi.UnregisterHotKey(windowHandleSource.Handle, id); registered.Remove(hotKey); } }
public void Textbox_SetValue(Keys eventKey, HotKeyInfo hotKey) { if (eventKey == Keys.Enter) { args.HotKey.ModKey = hotKey.ModKey; args.HotKey.Key = hotKey.Key; } Textbox_KeyDown(this, new KeyEventArgs(eventKey)); }
public ChooseHotKeyPage() { InitializeComponent(); HotKeySourceCombox.ItemsSource = lstHotKeySource; HotKeySourceCombox.SelectedIndex = 0; HotKey = new HotKeyInfo(); }
private static void Hook_OnKeyUpEvent(object sender, KeyEventArgs e) { var keyName = HotKeyInfo.GetStringByKey(e); if (m_hotkeyIndex.ContainsKey(keyName)) { var cmd = m_hotkeyIndex[keyName]; ahk.ExecRaw(cmd); //return (IntPtr)1; } //Console.WriteLine(e.KeyData.ToString()); }
// ショートカットキーの設定 private void ListViewShortcut_MouseDoubleClick(object sender, MouseEventArgs e) { ListViewHitInfo = ListViewShortcut.HitTest(e.X, e.Y); if (ListViewHitInfo.SubItem != null && e.Button == MouseButtons.Left) { Dll.SetKeyboardHook(true); HotKey = new HotKeyInfo(); ListViewInput = new ListViewInputBox(ListViewShortcut, ListViewHitInfo.Item, 1); ListViewInput.FinishInput += new ListViewInputBox.InputEventHandler(Input_FinishInput); ListViewInput.Disposed += new EventHandler(Input_Disposed); ListViewInput.Show(); } }
public bool AddKeys(Keys[] keys, KeyPressCallback callback) { if (keys == null || keys.Length == 0) return false; lock (myHotKeyList) { HotKeyInfo hki = new HotKeyInfo(keys, callback); if (!myHotKeyList.Contains(hki)) { myHotKeyList.Add(hki); return true; } } return false; }
/// <summary> /// ホットキーが登録可能か /// </summary> /// <param name="mod">修飾キー</param> /// <param name="key">キー</param> /// <returns>登録可能ならtrue</returns> public static bool CheckRegistHotKey(uint mod, uint key) { HotKeyInfo hotKey = new HotKeyInfo(mod, key); const int id = 9999; if (RegisterHotKey2(Launcher.Handle, id, hotKey) == 0) { return(false); } else { WinAPI.UnregisterHotKey(Launcher.Handle, id); return(true); } }
// ショートカットキー入力の確定 public bool Input_FinishInput(object sender, ListViewInputBox.InputEventArgs e) { Dll.SetKeyboardHook(false); if (ListViewHitInfo != null && ListViewHitInfo.SubItem != null) { int index = ListViewHitInfo.Item.Index; List <int> col = new List <int> { index }; if (PrevKeyStr[(int)ListViewHitInfo.Item.Tag] != e.NewName) { if (!GHManager.CheckRegistHotKey(e.HotKey.ModKey, e.HotKey.Key)) { col.Add(index); } } foreach (var item in GHManager.TempSettings.Hotkey.HotKeys.Select((kv, i) => new { kv, i })) { ListViewShortcut.Items[item.i].ForeColor = Color.FromKnownColor(KnownColor.WindowText); if ((int)ListViewHitInfo.Item.Tag == item.kv.Key) { continue; } if (e.HotKey.Equals(item.kv.Value)) { col.Add(item.i); } } if (col.Count > 1) { col.ForEach(i => ListViewShortcut.Items[i].ForeColor = Color.Red); } ListViewHitInfo.Item.SubItems[1].Text = e.NewName; GHManager.TempSettings.Hotkey.HotKeys[(int)ListViewHitInfo.Item.Tag].SetKeys(e.HotKey.ModKey, e.HotKey.Key); } else { return(false); } HotKey = null; return(true); }
public bool AddKeys(Keys[] keys, KeyPressCallback callback) { if (keys == null || keys.Length == 0) { return(false); } lock (myHotKeyList) { HotKeyInfo hki = new HotKeyInfo(keys, callback); if (!myHotKeyList.Contains(hki)) { myHotKeyList.Add(hki); return(true); } } return(false); }
private IntPtr MessagesHandler(IntPtr handle, int message, IntPtr wParam, IntPtr lParam, ref bool handled) { if (message == WinApi.WmHotKey) { // Extract key and modifiers from the message. var key = KeyInterop.KeyFromVirtualKey(((int)lParam >> 16) & 0xFFFF); var modifiers = (ModifierKeys)((int)lParam & 0xFFFF); var hotKey = new HotKeyInfo(key, modifiers); OnKeyPressed(new KeyPressedEventArgs(hotKey)); handled = true; return(new IntPtr(1)); } return(IntPtr.Zero); }
/// <summary> /// Registers the system-wide hot key. /// </summary> /// <param name="hotKey">The hot key.</param> public void Register(HotKeyInfo hotKey) { // Check if specified hot key is already registered. if (registered.ContainsKey(hotKey)) { throw new ArgumentException("热键已经被注册"); } // Register new hot key. var id = GetFreeKeyId(); if (!WinApi.RegisterHotKey(windowHandleSource.Handle, id, hotKey.Key, hotKey.Modifiers)) { throw new Win32Exception(Marshal.GetLastWin32Error(), "无法注册热键."); } registered.Add(hotKey, id); }
/// <summary> /// Registers a hot key in the system. /// </summary> /// <param name="modifier">The modifiers that are associated with the hot key.</param> /// <param name="key">The key itself that is associated with the hot key.</param> public void RegisterHotKey(ModifierKeys modifier, Keys key, Action callback) { var lookupKey = (int)modifier | ((int)key << 16); if (!_hotkeys.ContainsKey(lookupKey)) { _hotkeys[lookupKey] = new HotKeyInfo(); // register the hot key. if (!RegisterHotKey(Handle, _hotkeys[lookupKey].Id, (uint)modifier, (uint)key)) { _hotkeys.Remove(lookupKey); throw new InvalidOperationException("Couldn’t register the hot key."); } } _hotkeys[lookupKey].Callbacks.Add(callback); }
private void DelHotKey(string shortCutKey) { try { HotKeyInfo hkInfo = this.hotKeyInfoList.FindHotKey(shortCutKey); if (hkInfo == null) { return; } if (hkInfo.HOTKEY.Registered) { hkInfo.HOTKEY.Unregister(); } } catch (Exception ex) { ConsoleLib.ConsoleLib.WriteFormatted(ex.ToString() + " ", t); ConsoleLib.ConsoleLib.WriteLine(Environment.NewLine); } }
public BattleUnit(string name, UnitSide side, BattleUnitView view, Vector2Int pos) { Name = name; Image = "5"; Side = side; View = view; Steps = 3; Position = pos; HP = 100; HpMax = 100; MP = 100; MpMax = 100; Spirit = 100; SpiritMax = 100; Speed = 5; SpeedMax = 5; Attack = 100; Defence = 10; Dodge = 0; Shield = 0; Rebound = 0; DamageToManaShiled = 0; Crippled = false; SingTime = 0; CD = 0; HotKeys = new List <HotKeyInfo>(); HotKeyInfo info = new HotKeyInfo(); HotKeys.Add(info); Skills = new List <Skill>(); Skill skill = new Skill(); Skills.Add(skill); view.Init(); }
/// <summary> /// Unregisters previously registered hot key. /// </summary> /// <param name="key">The key.</param> /// <param name="modifiers">The key modifiers.</param> public void Unregister(Key key, ModifierKeys modifiers) { var hotKey = new HotKeyInfo(key, modifiers); Unregister(hotKey); }
/// <summary> /// Initializes a new instance of the <see cref="KeyPressedEventArgs"/> class. /// </summary> /// <param name="hotKey">The hot key.</param> public KeyPressedEventArgs(HotKeyInfo hotKey) { HotKey = hotKey; }
private static int RegisterHotKey2(IntPtr handle, int id, HotKeyInfo hotkey) { return(WinAPI.RegisterHotKey(handle, id, hotkey.WinAPI_ModKey, hotkey.WinAPI_Key)); }
public override int?Run(AugmentrexContext context, string[] args) { var opts = Parse <KeyOptions>(context, args); if (opts == null) { return(null); } if (!opts.Add && !opts.Delete) { foreach (var kvp in _bindings) { context.InfoLine("{0} = {1}", kvp.Key, kvp.Value); } return(null); } var info = new HotKeyInfo(opts.Key, opts.Alt, opts.Control, opts.Shift); if (_handler == null) { void KeyHandler(HotKeyInfo info) { var freq = context.Configuration.HotKeyBeepFrequency; if (freq != 0) { context.Ipc.Channel.Beep(freq, context.Configuration.HotKeyBeepDuration); } if (_bindings.TryGetValue(info, out var command)) { context.Interpreter.RunCommand(command, true); } } _handler = new HotKeyHandler(KeyHandler); } if (opts.Add) { var command = string.Join(" ", opts.Fragments); if (string.IsNullOrWhiteSpace(command)) { context.ErrorLine("No command given."); return(null); } if (_bindings.TryAdd(info, command)) { context.HotKeys.Add(info, _handler); context.InfoLine("Added key binding: {0} = {1}", info, command); } else { context.ErrorLine("Key binding already exists: {0} = {1}", info, _bindings[info]); } } if (opts.Delete) { if (_bindings.Remove(info, out var command)) { context.InfoLine("Deleted key binding: {0} = {1}", info, command); } else { context.ErrorLine("Key binding not found: {0}", info); } } return(null); }
/// <summary> /// Set global hotkey /// </summary> private void SetShortcutKey(ClipboardInfo selectedInfo) { try { ClipboardInfoList clipboardInfoList = this.GetClipboardInfoList; HotKeyInfo hkInfo = new HotKeyInfo(); if (selectedInfo != null) { string hotkey = selectedInfo.SHORTKEY; string hotkeyNum = hotkey.Substring(hotkey.LastIndexOf("+")+1); bool ctrl = hotkey.Contains("Ctrl"); bool alt = hotkey.Contains("Alt"); bool shift = hotkey.Contains("Shift"); // setting global hotKey Keys key = Keys.None; switch (hotkeyNum) { case "1": key = Keys.D1; break; case "2": key = Keys.D2; break; case "3": key = Keys.D3; break; case "4": key = Keys.D4; break; case "5": key = Keys.D5; break; case "6": key = Keys.D6; break; case "7": key = Keys.D7; break; case "8": key = Keys.D8; break; case "9": key = Keys.D9; break; case "0": key = Keys.D0; break; default: break; } Hotkey hk = this.SetHotKey(key, shift, ctrl, alt, false, selectedInfo); if (hk == null) return; hkInfo.HOTKEY = hk; hkInfo.HOTKEYNAME = hotkey; hotKeyInfoList.Add(hkInfo); } } catch (Exception ex) { ConsoleLib.ConsoleLib.WriteFormatted(ex.ToString() + " ", t); ConsoleLib.ConsoleLib.WriteLine(Environment.NewLine); } }
protected override void WndProc(ref Message xMessage) { var keyCode = xMessage.WParam.ToInt32(); var hotKeyInfo = HotKeyInfo.GetFromMessage(xMessage); if (hotKeyInfo != null) { if (hotKeyInfo.Modifiers == Modifiers.Alt && hotKeyInfo.Key == Keys.NumPad9) { int?maxPikeSin = CalcMove.PikeSin.OrderBy(n => n).Cast <int?>() .FirstOrDefault(n => n >= 9); if (maxPikeSin.HasValue) { CalcMove.PikeSin.Remove(maxPikeSin.Value); } } if (keyCode == AddGroup.Id) { int?maxPikeSin = CalcMove.PikeSin.OrderBy(n => n).Cast <int?>() .FirstOrDefault(n => n >= 9); if (!maxPikeSin.HasValue) { CalcMove.PikeSin.Add(9); } } if (keyCode == Rules.Id) { var sim = new InputSimulator(); sim.Keyboard.Sleep(1000) .TextEntry(Setting.Rules) .Sleep(1000); } if (keyCode == StartRecordPattern.Id) { Voice.PlaySound("//Voice//Start.wav"); FrmRecordShieldPattern = new FrmFormStatic(); FrmRecordShieldPattern.ShowDialog(); } if (keyCode == EndRecordPattern.Id) { var allPositionClick = HookManager.PositionClick; var stringData = JsonConvert.SerializeObject(allPositionClick); var newPatternName = Guid.NewGuid(); var newPattern = PatternShieldAddress + newPatternName.ToString() + ".txt"; if (!File.Exists(newPattern)) { var temp = File.Create(newPattern); temp.Close(); } File.AppendAllText(newPattern, stringData); FrmRecordShieldPattern.DialogResult = DialogResult.OK; Voice.PlaySound("//Voice//Ending.wav"); } } if (keyCode == (int)Keys.S) { Key.SendKey(keyCode, Setting); } if (keyCode == (int)Keys.W) { Key.SendKey(keyCode, Setting); } if (keyCode == (int)Keys.A) { Key.SendKey(keyCode, Setting); } if (keyCode == (int)Keys.D) { Key.SendKey(keyCode, Setting); } if (keyCode == (int)Keys.Q) { Key.SendKey(keyCode, Setting); } if (keyCode == (int)Keys.F6) { var pattern = Directory.GetFiles(PatternShieldAddress).ToList(); if (pattern.Count == 0) { return; } var r = new Random(); var choosePatternNumber = r.Next(0, pattern.Count - 1); var choosePattern = pattern[choosePatternNumber]; var readPattern = File.ReadAllText(choosePattern); var containPattern = JsonConvert.DeserializeObject <List <Point> >(readPattern); var c = Cursor.Position; foreach (Point point in containPattern) { Clicker.LeftClick(20); MouseMoves.LinearSmoothMove(point, Setting.MouseSpeed); Clicker.LeftClick(20); } } if (keyCode == (int)Keys.Decimal) { foreach (var i in CalcMove.PikeSin.Distinct()) { Key.MoveOne(i, Setting.CompressDelay); } } if (keyCode == (int)Keys.NumPad2) { if (ControlMode == ControlMode.Kn) { foreach (var i in CalcMove.Kn.Distinct()) { if (i == 1 || i == 2) { continue; } Key.MoveOne(i, Setting.CompressDelay); } } } if (keyCode == (int)Keys.Divide) { if (ControlMode == ControlMode.PikeSin) { ControlMode = ControlMode.Kn; btnKn.Text = "KN"; Voice.PlaySound("//Voice//Knight_s6.wav"); CalcMove.SetKn(CalcMove.Kn); CalcMove.Sort(); } else { ControlMode = ControlMode.PikeSin; btnKn.Text = "PikeSin"; Voice.PlaySound("//Voice//Knight_Disband1.wav"); CalcMove.SetPikeSin(); } } if (keyCode == (int)Keys.Subtract) { if (ControlMode == ControlMode.PikeSin) { CalcMove.SetPikeSin(); } else { if (CalcMove.Kn.Count != 0) { var bigger = CalcMove.Kn.Max(); CalcMove.Kn.Remove(bigger); CalcMove.PikeSin.Add(bigger); } } CalcMove.Sort(); } if (keyCode == (int)Keys.Multiply) { if (CalcMove.PikeSin.Count != 0) { CalcMove.PikeSin.Sort(); int smaller = 0; if (CalcMove.PikeSin.Count == 1) { smaller = CalcMove.PikeSin.Min(); } else { smaller = CalcMove.PikeSin.Skip(1).Min(); } CalcMove.PikeSin.Remove(smaller); CalcMove.Kn.Add(smaller); } CalcMove.Sort(); } if (keyCode == (int)Keys.NumPad1) { Key.SendKey(keyCode, Setting); } if (keyCode == (int)Keys.Add) { Key.SendKey(keyCode, Setting); } if (keyCode == (int)Keys.NumPad5) { Key.SendKey(keyCode, Setting); } if (keyCode == (int)Keys.N) { Key.SendKey(keyCode, Setting); } if (keyCode == (int)Keys.G) { Key.SendKey(keyCode, Setting); } if (keyCode == (int)Keys.M) { Key.SendKey(keyCode, Setting); } if (keyCode == (int)Keys.H) { Key.SendKey(keyCode, Setting); } if (keyCode == (int)Keys.B) { Key.SendKey(keyCode, Setting); } if (keyCode == (int)Keys.I) { Key.SendKey(keyCode, Setting); } if (keyCode == (int)Keys.E) { Key.SendKey(keyCode, Setting); } if (keyCode == (int)Keys.NumPad3) { AssassinFlag.Move(Setting.FlagDelay); } if (keyCode == (int)Keys.Insert) { if (checkBox2.Checked == false) { System.Media.SoundPlayer player = new System.Media.SoundPlayer(Environment.CurrentDirectory + "//Voice//Engineer_catplt1.wav"); player.Load(); player.Play(); this.BackColor = Color.CornflowerBlue; RegisterKey(); btnActive.Text = "Active ON (Insert)"; btnActive.ForeColor = Color.DodgerBlue; checkBox2.Checked = true; return; } if (checkBox2.Checked) { System.Media.SoundPlayer player = new System.Media.SoundPlayer(Environment.CurrentDirectory + "//Voice//AEngineer_Exit1.wav"); player.Load(); player.Play(); this.BackColor = Color.Coral; UnRegisterKey(); btnActive.Text = "Active OFF (Insert)"; btnActive.ForeColor = Color.Crimson; checkBox2.Checked = false; return; } } if (keyCode == (int)Keys.F4) { var shieldPosition = new Point(Cursor.Position.X, Cursor.Position.Y); Clicker.LeftClick(130, 700, Setting.CompressDelay); Clicker.LeftClick(shieldPosition.X, shieldPosition.Y, Setting.CompressDelay); } if (keyCode == (int)Keys.F5) { var shieldPosition = new Point(Cursor.Position.X, Cursor.Position.Y); Clicker.LeftClick(173, 745, Setting.CompressDelay); Clicker.LeftClick(shieldPosition.X, shieldPosition.Y, Setting.CompressDelay); } if (keyCode == (int)Keys.End || keyCode == (int)Keys.PageDown) { // var tc = new Random(); // var index = tc.Next(1, ValidPoint.Count - 1); // MouseMoves.LinearSmoothMove(new Point(Cursor.Position.X, Cursor.Position.Y), int.Parse(textBox7.Text)); // MouseMoves.LinearSmoothMove(new Point(ValidPoint[index].X, ValidPoint[index].Y), int.Parse(textBox7.Text)); // Clicker.LeftClick(ValidPoint[index].X, ValidPoint[index].Y, Setting.CompressDelay); } base.WndProc(ref xMessage); }