private static bool OnHotkeyPressed(int key, int mod, bool pressed) { Key keys = SDLKeyToKeys(key); if (pressed) { HotkeyPressedEvent?.Invoke(key, mod, keys, IntToModKey(mod)); bool pass = HotkeyManager.GetInstance().OnHotkeyPressed(keys, IntToModKey(mod)); return(!pass); } return(true); }
private void OnHotkeyPressed(object o, HotkeyPressedEvent e) { var handle = handleService.GetHandle("Diablo III64"); if (e.PressedHotkey.KeyCode == Keys.Escape && e.PressedHotkey.Modifiers == Keys.None && tokenSource == null) { InputHelper.SendKey(WindowHelper.GetForegroundWindow(), Keys.Escape); } if (handle.IsDefault()) { return; } var actionName = settingsService.GetActionName(e.PressedHotkey); if (actionName == ActionName.Pause || (e.PressedHotkey.KeyCode == Keys.Escape && e.PressedHotkey.Modifiers == Keys.None)) { if (tokenSource != null) { tokenSource.Cancel(); logService.AddEntry(this, $"Cancelling current action... [{actionName}][{e.PressedHotkey}]"); } } else if (actionName.IsCancelable()) { if (tokenSource == null) { tokenSource = new CancellationTokenSource(); var macro = actionFinderService.FindAction(actionName, handle.Handle, tokenSource); ExecuteAndResetTokenSourceAsync(macro); logService.AddEntry(this, $"Beginning to execute... [{actionName}][{e.PressedHotkey}]"); } else { tokenSource.Cancel(); logService.AddEntry(this, $"Cancelling current action... [{actionName}][{e.PressedHotkey}]"); } } else if (!actionName.IsSuspensionAction()) { var macro = actionFinderService.FindAction(actionName, handle.Handle); Execute.AndForgetAsync(macro); logService.AddEntry(this, $"Beginning to execute... [{actionName}][{e.PressedHotkey}]"); } }