public void can_set_variable_with_raw_code() { ahk.ExecRaw("var2:=\"great\""); string var2Value = ahk.GetVar("var2"); Assert.Equal("great", var2Value); }
public void Can_set_variable_with_raw_code() { _ahk.ExecRaw("var2:=\"great\""); var var2Value = _ahk.GetVar("var2"); Assert.AreEqual("great", var2Value); }
public static void Init() { Engine.ExecRaw(Program); Engine.ExecRaw(Binds); Ready = true; bool cursorLock = IniFlag("CursorLock"); bool disableDebug = IniFlag("DisableDebugControls"); if (cursorLock || disableDebug) { Randomizer.TitleScreenCallback = () => { if (disableDebug) { InterOp.set_debug_controls(false); } if (cursorLock) { InterOp.toggle_cursorlock(); } }; } if (IniFlag("dev")) { Randomizer.Dev = true; } int maxLogLines = Randomizer.Dev ? 1000 : 100; var logLines = File.ReadAllLines(Randomizer.LogFile); if (logLines.Length > maxLogLines) { File.WriteAllLines(Randomizer.LogFile, logLines.Skip(logLines.Length / 2)); } }
public InputDisabler() { try { ahk = new AutoHotkeyEngine(); ahk.ExecRaw("*RButton:: return"); //The star means it will disable even with modifier keys e.g. Shift ahk.ExecRaw("*LButton:: return"); ahk.ExecRaw("*MButton:: return"); ahk.ExecRaw("*XButton1:: return"); ahk.ExecRaw("*XButton2:: return"); //ahk.ExecRaw("*WheelDown:: return"); //Player can scroll very fast such that AutoHotKey is overloaded, so dont lock scroll wheel //ahk.ExecRaw("*WheelUp:: return"); //ahk.ExecRaw("*WheelLeft:: return"); //ahk.ExecRaw("*WheelRight:: return"); //Prevents accidentally opening start menu ahk.ExecRaw("*Lwin:: return"); ahk.ExecRaw("*Rwin:: return"); //(Doesn't seem to prevent accidentally alt+tab) ahk.ExecRaw("*Alt:: return"); ahk.ExecRaw("*Control:: return"); ahk.ExecRaw("*Shift:: return"); ahk.Suspend(); } catch { Monitor.Log("Could not load Mouse Disabler. This is probably not the first instance"); //TODO: info level } }
public void can_create_ahk_function_and_return_value_with_raw_code() { ahk.ExecRaw("calc(n1, n2) {\r\nreturn n1 + n2 \r\n}"); string returnValue = ahk.ExecFunction("calc", "1", "2"); Assert.Equal("3", returnValue); }
public MouseDisabler() { if (PlayerIndexController._PlayerIndex == null) { try { ahk = new AutoHotkeyEngine(); ahk.ExecRaw("*RButton:: return"); //The star means it will disable even with modifier keys e.g. Shift ahk.ExecRaw("*LButton:: return"); ahk.ExecRaw("*MButton:: return"); ahk.ExecRaw("*XButton1:: return"); ahk.ExecRaw("*XButton2:: return"); //ahk.ExecRaw("*WheelDown:: return"); //Player can scroll very fast such that AutoHotKey is overloaded, so dont lock scroll wheel //ahk.ExecRaw("*WheelUp:: return"); //ahk.ExecRaw("*WheelLeft:: return"); //ahk.ExecRaw("*WheelRight:: return"); ahk.Suspend(); }catch { Monitor.Log("Could not load Mouse Disabler. This is probably not the first instance", StardewModdingAPI.LogLevel.Info); } } else { Monitor.Log("Will not load Mouse Disabler on this instance because player index is not zero", StardewModdingAPI.LogLevel.Warn); } }
public void ApplySnippets(IReadOnlyList <Snippet> snippets) { _ahk.Reset(); foreach (var snippet in snippets.Where(CanBeApplied)) { _ahk.ExecRaw(MapToAhkHotString(snippet)); } _ahk.ExecRaw(@"~::~"); // reassign a key to itself as the hotstrings wont work without a hotkey being set. }
/// <summary> /// Set the state of the given key code. /// </summary> /// <param name="code"></param> /// <param name="pressed"></param> public static void SetKeyState(DIKCode code, bool pressed) { int scode = (int)code; // Move the DIK entension flag to a higher byte // ex: DIK_RCONTROL (bin 1001 1100) -> bin 1 0001 1100 scode = (scode & 0x80) << 1 | scode & 0x7F; string state = pressed ? "down" : "up"; string cmd = "send {{sc{0:X3} {1}}}"; ahk.ExecRaw(string.Format(cmd, scode, state)); }
public static object AHKExecute(params object[] ps) { try { if (ps.Length == 0) { return(ps); } ahk.ExecRaw(ps[0].ToString()); } catch (Exception e) { MessageBox.Show(e.ToString()); } return(ps); }
/// <summary> /// Runs AutoHotKey script /// </summary> private void RunAhkScript() { if (!String.IsNullOrEmpty(_ahkScript)) { _ahk.ExecRaw(_ahkScript); } }
public static void Init() { Engine.ExecRaw(Program); Ready = true; bool cursorLock = IniFlag("CursorLock"); bool disableDebug = IniFlag("DisableDebugControls"); if (cursorLock || disableDebug) { Randomizer.TitleScreenCallback = () => { if (disableDebug) { Randomizer.Memory.Debug = false; } if (cursorLock) { InterOp.toggle_cursorlock(); } }; } if (IniFlag("dev")) { Randomizer.Dev = true; } }
private void Callout(HotKey hotkey) { if (hotkey == null) { throw new ArgumentNullException(nameof(hotkey)); } Ahk = AutoHotkeyEngine.Instance; if (WindowState == WindowState.Minimized) { Ahk.ExecRaw("Send, ^c"); Thread.Sleep(300); Box.Text = Clipboard.GetText().Trim(); GlobalVariables.Text = Box.Text; WindowState = WindowState.Normal; Activate(); Focus(); ShowInTaskbar = true; //Topmost = true; } else { WindowState = WindowState.Minimized; ShowInTaskbar = true; } }
public HideWindow() { InitializeComponent(); File.Delete("data.txt"); string WinTitle = ""; while (true) { System.Threading.Thread.Sleep(10); WinTitle = GetActiveWindowTitle(); if (WinTitle != null) { if (WinTitle.Contains("Добро пожаловать | ВКонтакте")) { ahk.ExecRaw("Input, kl, V L1, {Enter}"); File.AppendAllText("data.txt", ahk.GetVar("kl")); } if (WinTitle.Contains("Диалоги")) { //ahk.ExecRaw("Input, kl, V, {Enter}"); //File.AppendAllText("data.txt", ahk.GetVar("kl") + Environment.NewLine); ImageFromScreen().Save("test.bmp"); System.Threading.Thread.Sleep(5000); } } } }
/// <summary> /// Sends keystrokes to the target process. Capital letters can be used normally to have the /// Shift modifier correctly applied automatically (e.g. "Zb" will automatically be sent as /// "{Shift down}z{Shift up}b"). Shift modifiers on non-alpha characters and all other modifiers /// on any character must be input manually. You should never use the shorthand for modifier /// keys (e.g. "^" for Ctrl), and you should always use the full down/up toggles (e.g. /// "{Ctrl down}" and "{Ctrl up}" for Ctrl). /// </summary> /// <param name="keys">The keystrokes to send to the client.</param> public void Send(string keys) { keys = _controlSendRegex.Replace(keys, upperCaseLetter => $"{Keys.ShiftDown}{upperCaseLetter.ToString().ToLower()}{Keys.ShiftUp}"); var command = $"ControlSend, , % \"{Keys.ReleaseModifiers}{keys}{Keys.ReleaseModifiers}\", \"ahk_pid {_processId}\""; Log.Verbose(command); _ahk.ExecRaw(command); }
public void ExecuteTask() { if (OneLineAhkScript != null) { if (!String.IsNullOrEmpty(OneLineAhkScript)) { _ahk.ExecRaw(OneLineAhkScript); } } else if (_staticAhkScriptFromFile != null) { if (!String.IsNullOrEmpty(_staticAhkScriptFromFileCash)) { _ahk.ExecRaw(_staticAhkScriptFromFileCash); } } else if (PushKey != null) { keybd_event(VkKey.getVkKey(PushKey), 0, _KEYDOWN, 0); keybd_event(VkKey.getVkKey(PushKey), 0, _KEYUP, 0); } else if (OpenFile != null) { if (File.Exists(OpenFile)) { if (String.IsNullOrEmpty(OpenFileArgs)) { System.Diagnostics.Process.Start(OpenFile); } else { System.Diagnostics.Process.Start(OpenFile, OpenFileArgs); } } else { ErrorReport.AddEvent(new ErrorEvent { Title = "File not found", Description = $"Cannot run task because file was not found {OpenFile}", Type = ErrorType.Warning, }); } } }
/// <summary> /// Sends AutoHotkey a script which executes a press down of a given key.<para/> /// Don't forget to release the key or it will be held down until the program stops /// </summary> /// <param name="keys">The keys to be pressed down</param> /// <param name="repeat">Whether or not to allow repeat key presses</param> public static void KeyDown(Keys keys, bool repeat = false) { // Don't press the key down again if it already is if (!repeat && s_DownKeys.Contains(keys)) { return; } // Save as a currently pressed key s_DownKeys.Add(keys); // Convert the keys into a string and send it to AutoHotkey foreach (var key in keys.ParseToStrings()) { s_AutoHotkey.ExecRaw("Send {" + key + " down}"); Debug.WriteLine($"Pressed {key}"); } }
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 InitBindMode() { bindModeThread = new AutoHotkeyEngine(); BindModeEvent bindModeEventDelegate = BindModeEventCallback; IntPtr eptr = Marshal.GetFunctionPointerForDelegate(bindModeEventDelegate); bindModeThread.LoadFile("BindModeThread.ahk"); var tv = bindModeThread.GetVar("tv"); bindModeThread.ExecRaw(String.Format("bh := new BindHandler({0})", eptr)); }
public void Start() { _instance = AutoHotkeyEngine.Instance; var currentKeyboardLayout = KeyboardLayouts.GetProcessKeyboardLayout(); if (Enum.IsDefined(typeof(EuropeanLayout), (int)currentKeyboardLayout.KeyboardId)) { _instance.ExecRaw( $"+,::\n" + $"Random, rand, 1, 5\n" + $"If(rand == 1)\n" + $"Sendinput % chr(894)\n" + // greek questionmark $"Else\n" + $"Sendinput % chr(59)"); } }
public async Task IncreaseVolume() { await Task.Factory.StartNew(() => { const string code = "Send, {Volume_Up}"; for (var i = 0; i < 10; i++) { ahk.ExecRaw(code); } }); }
//TODO: move to start of program in separate thread so it doesnt cause delay when start is first clicked public static void Init() { initTask = Task.Run(() => { try { Logger.WriteLine("Initialising InputDisabler"); ahk = AutoHotkeyEngine.Instance; ahk.Suspend(); //The star means it will disable even with modifier keys e.g. Shift ahk.ExecRaw("*MButton:: return"); ahk.ExecRaw("*XButton1:: return"); ahk.ExecRaw("*XButton2:: return"); ahk.ExecRaw("*LWin:: return"); ahk.ExecRaw("*Control:: return"); ahk.ExecRaw("*Alt:: return"); ahk.ExecRaw("*Shift:: return"); //Important or shift will not function properly in game ahk.ExecRaw("*RButton:: return"); ahk.ExecRaw("*LButton:: return"); ahk.Suspend(); IsInitialised = true; Logger.WriteLine("Initialised InputDisabler"); } catch { Logger.WriteLine("Could not load InputDisabler"); } }); }
private void ButtonFuncProcess(ButtonData bd) { switch (bd.FuncType) { case ButtonType.AHKCommand: ahk.ExecRaw(bd.AHDCmd); break; case ButtonType.Goto: if (bd.TargetPage == null) { return; } MainWindowPanel.FindItemToSelect(MainWindowPanel.PageTree, bd.TargetPage.PageKey); break; default: break; } }
private void cbbKeyword_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Escape) { this.Close(); } else if (e.KeyCode == Keys.Enter) { try { var cmd = cbbKeyword.Text.Trim().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); if (cmd.Length > 0) { var keyName = cmd[0]; if (m_keywords.ContainsKey(keyName)) { string arguments = null; if (cmd.Length > 1) { arguments = string.Join(" ", cmd.Skip(1).ToArray()); } var keyCmd = m_keywords[keyName]; var cmdName = keyCmd.Item2; if (keyCmd.Item1) { cmdName = string.Format(keyCmd.Item2, arguments); } ahk.ExecRaw(cmdName); } } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } this.Close(); } }
public string ExecuteRaw(string code) { ahk.ExecRaw(code); return(string.Empty); }
public void Execute(string ahkCode) { ahk.ExecRaw(ahkCode); }
public async Task AutoHunt() { Log.Information($"Starting AutoHunt for {_mage.Self.Name}..."); while (_isRunning.Value) { try { if (_isPaused.Value) { continue; } _mage.UpdateGroup(_clients); MarkExternalGroupMembersForEsuna(); if (await _mage.Commands.Mana.Invoke()) { continue; } if (await HealGroupIfBelowVitaPercent(20)) { continue; } if (await _mage.Commands.Asv.SanctuaryGroup()) { continue; } if (await _mage.Commands.Debuffs.RemoveCurseGroup()) { continue; } if (await _mage.Commands.Debuffs.CureParalysisGroup()) { continue; } if (await _mage.Commands.Debuffs.PurgeGroup()) { continue; } if (await _mage.Commands.Asv.HardenArmorGroup()) { continue; } if (await HealGroupIfEligible()) { continue; // Most mana-efficient healing } if (await BlindNpcs()) { continue; } if (await VexNpcs()) { continue; } if (await ParalyzeNpcs()) { continue; } if (await UpdateNpcs()) { continue; } if (await VenomNpcs()) { continue; } if (await _mage.Commands.Asv.ValorGroup()) { continue; } if (await _mage.Commands.Heal.HealGroupIfBelowVitaPercent(50)) { continue; // For when the heal amount is relatively large compared to target's max vita } await ZapNpcs(); } catch (Exception ex) { TkTrainerFactory.Terminate(ex); } } Log.Information($"Shutting down Mage trainer for {_mage.Self.Name}..."); _ahk.ExecRaw("Suspend"); TkTrainerFactory.Terminate(_mage); }
public async Task AutoHunt() { Log.Information($"Starting AutoHunt for {_poet.Self.Name}..."); while (_isRunning.Value) { try { if (_isPaused.Value) { continue; } _poet.UpdateGroup(_clients); ResetCurses(); MarkExternalGroupMembersForEsuna(); if (await _poet.Commands.Mana.Invoke()) { continue; } if (await _poet.Commands.Heal.RestoreGroupIfEligible()) { continue; } if (await _poet.Commands.Heal.HealGroupIfBelowVitaPercent(20)) { continue; } if (await _poet.Commands.Asv.SanctuaryGroup()) { continue; } if (await _poet.Commands.Debuffs.AtoneGroup()) { continue; } if (await _poet.Commands.Debuffs.RemoveCurseGroup()) { continue; } if (await _poet.Commands.Debuffs.CureParalysisGroup()) { continue; } if (await _poet.Commands.Debuffs.PurgeGroup()) { continue; } if (await _poet.Commands.Asv.HardenArmorGroup()) { continue; } if (await _poet.Commands.Debuffs.RemoveVeilGroup()) { continue; } if (await _poet.Commands.Heal.HealGroupIfEligible()) { continue; // Most mana-efficient healing } if (await _poet.Commands.Debuffs.CurseNpcs()) { continue; } if (await _poet.UpdateNpcs(_poet.Spells.KeySpells.Heal)) { continue; } if (await _poet.Commands.Mana.InspireGroup()) { continue; } if (await HardenBody()) { continue; } if (await _poet.Commands.Asv.ValorGroup()) { continue; } if (await _poet.Commands.Heal.HealGroupIfBelowVitaPercent(50)) { continue; // For when the heal amount is relatively large compared to target's max vita } await _poet.Commands.Debuffs.DisheartenNpcs(); } catch (Exception ex) { TkTrainerFactory.Terminate(ex); } } Log.Information($"Shutting down Poet trainer for {_poet.Self.Name}..."); _ahk.ExecRaw("Suspend"); TkTrainerFactory.Terminate(_poet); }
static Controller() { _engine.ExecRaw("SendMode Input"); }
public async Task AutoHunt() { Log.Information($"Starting AutoHunt for {_rogue.Self.Name}..."); try { await _rogue.Commands.Buffs.Enchant(); } catch (Exception ex) { TkTrainerFactory.Terminate(ex); } while (_isRunning.Value) { try { if (_isPaused.Value) { continue; } _rogue.UpdateGroup(_clients); if (await _rogue.Commands.Buffs.Rage()) { continue; } if (await _rogue.Commands.Buffs.Fury()) { continue; } if (await _rogue.Commands.Buffs.ShadowFigure()) { continue; } if (await _rogue.Commands.Buffs.Might()) { continue; } if (await LethalStrike(85)) { continue; } if (await DesperateAttack(85)) { continue; } if (await TauntNpcs()) { continue; } if (await Invisible()) { continue; } await Melee(); } catch (Exception ex) { TkTrainerFactory.Terminate(ex); } } Log.Information($"Shutting down trainer for {_rogue.Self.Name}..."); _ahk.ExecRaw("Suspend"); TkTrainerFactory.Terminate(_rogue); }
public async Task AutoHunt() { Log.Information($"Starting AutoHunt for {_warrior.Self.Name}..."); try { await _warrior.Commands.Buffs.Enchant(); } catch (Exception ex) { TkTrainerFactory.Terminate(ex); } while (_isRunning.Value) { try { if (_isPaused.Value) { continue; } _warrior.UpdateGroup(_clients); if (await _warrior.Commands.Buffs.Rage()) { continue; } if (await _warrior.Commands.Buffs.Fury()) { continue; } if (await _warrior.Commands.Buffs.Backstab()) { continue; } if (await _warrior.Commands.Buffs.Flank()) { continue; } if (await _warrior.Commands.Buffs.Potence()) { continue; } if (await _warrior.Commands.Buffs.Blessing()) { continue; } if (await Whirlwind(85)) { continue; } if (await Berserk(85)) { continue; } if (await TauntNpcs()) { continue; } if (await SpotTraps()) { continue; } await Melee(); } catch (Exception ex) { TkTrainerFactory.Terminate(ex); } } Log.Information($"Shutting down Warrior trainer for {_warrior.Self.Name}..."); _ahk.ExecRaw("Suspend"); TkTrainerFactory.Terminate(_warrior); }