Пример #1
0
        static void Main(string[] args)
        {
            //create an autohtkey engine.
            var ahk = new AutoHotkey.Interop.AutoHotkeyEngine();

            //execute any raw ahk code
            ahk.ExecRaw("MsgBox, Hello World!");

            //create new hotkeys
            ahk.ExecRaw("^a::Send, Hello World");

            //programmatically set variables
            ahk.SetVar("x", "1");
            ahk.SetVar("y", "4");

            //execute statements
            ahk.ExecRaw("z:=x+y");

            //return variables back from ahk
            string zValue = ahk.GetVar("z");

            Console.WriteLine("Value of z is {0}", zValue); // "Value of z is 5"

            //Load a library or exec scripts in a file
            ahk.Load("functions.ahk");

            //execute a specific function (found in functions.ahk), with 2 parameters
            ahk.ExecFunction("MyFunction", "Hello", "World");

            //execute a label
            ahk.ExecLabel("DOSTUFF");

            //create a new function
            string sayHelloFunction = "SayHello(name) \r\n { \r\n MsgBox, Hello %name% \r\n return \r\n }";

            ahk.ExecRaw(sayHelloFunction);

            //execute's newly made function\
            ahk.ExecRaw(@"SayHello(""Mario"") ");


            //execute a function (in functions.ahk) that adds 5 and return results
            var add5Results = ahk.Eval("Add5( 5 )");

            Console.WriteLine("Eval: Result of 5 with Add5 func is {0}", add5Results);

            //you can also return results with the ExecFunction
            add5Results = ahk.ExecFunction("Add5", "5");
            Console.WriteLine("ExecFunction: Result of 5 with Add5 func is {0}", add5Results);


            Console.WriteLine("Press enter to exit...");
            Console.ReadLine();
        }
Пример #2
0
 public ScanAndFire()
 {
     lastKeys = new SortedList <uint, DateTime>();
     ahk      = new AutoHotkey.Interop.AutoHotkeyEngine();
     ahk.ExecRaw("CoordMode, ToolTip, Screen");
     ahk.ExecRaw("CoordMode, Pixel, Screen");
     ahk.ExecRaw("CoordMode, Mouse, Screen");
     ahk.ExecRaw("CoordMode, Caret, Screen");
     ahk.ExecRaw("CoordMode, Menu, Screen");
     Task.Run(new Action(RunService));
 }
Пример #3
0
        private void RegisterHotKeys()
        {
            var script = new StringBuilder();

            foreach (var hotkey in _shortcutCallbackMap.Keys)
            {
                script.AppendLine($"{hotkey}::Run,Pastr.Messaging.exe {hotkey}");
            }

            _ahkEngine.ExecRaw(script.ToString());
        }
Пример #4
0
        static void Main(string[] args)
        {
            //create an autohtkey engine.
            var ahk = new AutoHotkey.Interop.AutoHotkeyEngine();

            //execute any raw ahk code
            ahk.ExecRaw("MsgBox, Hello World!");

            //create new hotkeys
            ahk.ExecRaw("^a::Send, Hello World");
            
            //programmatically set variables
            ahk.SetVar("x", "1");
            ahk.SetVar("y", "4");

            //execute statements
            ahk.ExecRaw("z:=x+y");

            //return variables back from ahk
            string zValue = ahk.GetVar("z");
            Console.WriteLine("Value of z is {0}", zValue); // "Value of z is 5"

            //Load a library or exec scripts in a file
            ahk.Load("functions.ahk");

            //execute a specific function (found in functions.ahk), with 2 parameters
            ahk.ExecFunction("MyFunction", "Hello", "World");

            //execute a label 
            ahk.ExecLabel("DOSTUFF");

            //create a new function
            string sayHelloFunction = "SayHello(name) \r\n { \r\n MsgBox, Hello %name% \r\n return \r\n }";
            ahk.ExecRaw(sayHelloFunction);

            //execute's newly made function\
            ahk.ExecRaw(@"SayHello(""Mario"") ");


            //execute a function (in functions.ahk) that adds 5 and return results
            var add5Results = ahk.Eval("Add5( 5 )");
            Console.WriteLine("Eval: Result of 5 with Add5 func is {0}", add5Results);

            //you can also return results with the ExecFunction 
            add5Results = ahk.ExecFunction("Add5", "5");
            Console.WriteLine("ExecFunction: Result of 5 with Add5 func is {0}", add5Results);

            
            Console.WriteLine("Press enter to exit...");
            Console.ReadLine();
        }
Пример #5
0
        /// <summary>
        /// Some commands require sending keys directly to Spotify (for example, Fast Forward and Rewind which
        /// are not handled by Spotify). We can't inject keys directly with WM_KEYDOWN/UP since we need a keyboard
        /// hook to actually change the state of various modifier keys (for example, Shift + Right for Fast Forward).
        ///
        /// AutoHotKey has that hook and can modify the state for us, so let's take advantge of it.
        /// </summary>
        /// <param name="keys"></param>
        private static void SendComplexKeys(string keys)
        {
            // Is this nicer?
            // _ahk = _ahk ?? new AutoHotkey.Interop.AutoHotkeyEngine();

            // only initialize AHK when needed as it can be expensive (dll copy etc) if not actually needed
            if (_ahk == null)
            {
                _ahk = new AutoHotkey.Interop.AutoHotkeyEngine();
            }

            _ahk.ExecRaw("SetTitleMatchMode 2");

            _ahk.ExecRaw("DetectHiddenWindows, On");
            _ahk.ExecRaw("ControlSend, ahk_parent, " + keys + ", ahk_class SpotifyMainWindow");

            _ahk.ExecRaw("DetectHiddenWindows, Off");
        }
Пример #6
0
        private void RunService()
        {
            while (true)
            {
                ahk.ExecRaw("state:= GetKeyState(\"Capslock\", \"T\")");
                bool capsOn = (ahk.GetVar("state") == "1");

                if (capsOn)
                {
                    ServiceLoop();
                    Thread.Sleep(50);
                }
                else
                {
                    Thread.Sleep(100);
                }
            }
        }
Пример #7
0
        public override void Execute(ActionContext context)
        {
            try
            {
                var ahk = new AutoHotkey.Interop.AutoHotkeyEngine();
                ahk.ExecRaw(RawScript);
                while (ahk.IsReady() == true)
                {
                    System.Threading.Thread.Sleep(100);
                }

                ahk.Reset();
                // MessageBox.Show("Engine finished.");
            }
            catch (Exception e)
            {
                if (e is ActionException)
                {
                    throw;
                }

                throw new ActionException("ActionError", e.Message, e.InnerException);
            }
        }