public void OnActionExecuting(ActionExecutingContext context)
        {
            AKeys  ak      = new AKeys();
            string api_key = (string)context.HttpContext.Request.Query["API_KEY"];

            if (ak.Api_keys.IndexOf(api_key) == -1)
            {
                context.Result = new ContentResult()
                {
                    Content = "Ошибка 403 Forbidden"
                };
            }
        }
Пример #2
0
    /// <summary>
    /// Inserts text in specified or focused control.
    /// At current position, not as new line, replaces selection.
    /// </summary>
    /// <param name="c">If null, uses the focused control, else sets focus.</param>
    /// <param name="s">If contains '%', removes it and moves caret there.</param>
    public static void TextSimplyInControl(System.Windows.Forms.Control c, string s)
    {
        if (c == null)
        {
            c = AWnd.ThisThread.FocusedControl;
            if (c == null)
            {
                return;
            }
        }
        else
        {
            c.Focus();
        }

        int i = s.IndexOf('%');

        if (i >= 0)
        {
            Debug.Assert(!s.Contains('\r'));
            s = s.Remove(i, 1);
            i = s.Length - i;
        }

        if (c is AuScintilla sci)
        {
            if (sci.Z.IsReadonly)
            {
                return;
            }
            sci.Z.ReplaceSel(s);
            while (i-- > 0)
            {
                sci.Call(Sci.SCI_CHARLEFT);
            }
        }
        else
        {
            Task.Run(() => {
                var k = new AKeys(null);
                k.AddText(s);
                if (i > 0)
                {
                    k.AddKey(KKey.Left).AddRepeat(i);
                }
                k.Send();
            });
        }
    }
Пример #3
0
    void AutotextTriggers()
    {
        var tt = Triggers.Autotext;
        var tr = Triggers.Autotext.SimpleReplace;

        //examples of autotext triggers

        tt["los"] = o => o.Replace("Los Angeles");
        tt["WIndows", TAFlags.MatchCase] = o => o.Replace("Windows");

        tt.DefaultPostfixType = TAPostfix.None; //set some options for triggers added afterwards
        tt["<b>"]             = o => o.Replace("<b>[[|]]</b>");

        Triggers.Options.BeforeAction = o => { AOpt.Key.TextOption = KTextOption.Paste; }; //set AOpt options for trigger actions added afterwards
        tt["#file"] = o => {
            o.Replace("");
            using var fd = new System.Windows.Forms.OpenFileDialog();
            if (fd.ShowDialog() != System.Windows.Forms.DialogResult.OK)
            {
                return;
            }
            AKeys.Text(fd.FileName);
        };

        Triggers.Options.BeforeAction = null; tt.DefaultPostfixType = default; //reset some options

        //examples of simple text replacements

        tr["#su"] = "Sunday"; //the same as tt["#su"] = o => o.Replace("Sunday");
        tr["#mo"] = "Monday";

        //these triggers will work only in Notepad window

        Triggers.Of.Window("* Notepad", "Notepad");
        tr["#tu"] = "Tuesday";
        tr["#we"] = "Wednesday";
        Triggers.Of.AllWindows(); //reset

        //with confirmation

        tt.DefaultFlags |= TAFlags.Confirm; //add flag
        tr["#th"]        = "Thursday";
        tr["#fr", postfixType : TAPostfix.None] = "Friday";
        tt.DefaultFlags &= ~TAFlags.Confirm; //remove flag

        //To add triggers can be used snippets. Start typing "trig" and you will see snippets in the completion list.
    }
Пример #4
0
    void HotkeyTriggers()
    {
        var hk = Triggers.Hotkey;

        //examples of hotkey triggers

        hk["Ctrl+Alt+K"]     = o => AOutput.Write(o.Trigger); //it means: when I press Ctrl+Alt+K, execute action "AOutput.Write(o.Trigger)"
        hk["Ctrl+Shift+F11"] = o => {                         //action can have multiple statements
            var w1 = AWnd.FindOrRun("* Notepad", run: () => AExec.Run(AFolders.System + "notepad.exe"));
            AKeys.Text("text");
            500.ms();
            w1.Close();
        };
        hk["Ctrl+Shift+1"] = o => TriggerActionExample();          //action code can be in other function. To find it quickly, Ctrl+click the function name here.
        hk["Ctrl+Shift+2"] = o => TriggerActionExample2(o.Window); //the function can be in any class or partial file of this project folder
        hk["Ctrl+Shift+3"] = o => ATask.Run("Script example1.cs"); //run script in separate process. Then don't need to restart triggers when editing the script.

        //triggers that work only with some windows (when the window is active)

        Triggers.Of.Window("* WordPad", "WordPadClass");

        hk["Ctrl+F5"] = o => AOutput.Write("action 1", o.Trigger, o.Window);
        //hk[""] = o => {  };
        //...

        Triggers.Of.Windows(",,notepad.exe"); //all windows of notepad.exe process

        hk["Ctrl+F5"] = o => AOutput.Write("action 2", o.Trigger, o.Window);
        //hk[""] = o => {  };
        //...

        //...

        //disable/enable triggers
        Triggers.Of.AllWindows();
        hk["Ctrl+Alt+Win+D"]  = o => ActionTriggers.DisabledEverywhere ^= true;
        hk.Last.EnabledAlways = true;

        //To add triggers can be used snippets. Start typing "trig" and you will see snippets in the completion list.
        //For more info click word ActionTriggers above and press F1.
    }
Пример #5
0
partial class Script : AScript { [STAThread] static void Main(string[] a) => new Script(a); Script(string[] args)   //;;;
//Click the ► button on the toolbar to run the script.

                                 {
                                     AOutput.Write("The programming language is C#.");
                                     if (ADialog.ShowYesNo("Run Notepad?", "The script will add some text and close Notepad after 2 s."))
                                     {
                                         AExec.Run(AFolders.System + @"Notepad.exe");
                                         var w = AWnd.Wait(5, active: true, "*- Notepad"); //to create this code can be used the Code menu
                                         50.ms();
                                         AKeys.Text("some text");
                                         2.s();
                                         AKeys.Key("Ctrl+Z"); //Undo
                                         w.Close();
                                     }

                                     string linkText = "Read about code editor features",
                                            linkUrl  = "https://www.quickmacros.com/au/help/editor/Code editor.html";

                                     AOutput.Write($"<><link \"{linkUrl}\">{linkText}</link>");
                                 }
Пример #6
0
        /// <summary>
        /// Gets left and right modifiers. Uses AKeys.IsPressed.
        /// Returns modL | modR.
        /// </summary>
        public static KMod GetModLR(out KMod modL, out KMod modR)
        {
            KMod L = 0, R = 0;

            if (AKeys.IsPressed(KKey.LCtrl))
            {
                L |= KMod.Ctrl;
            }
            if (AKeys.IsPressed(KKey.LShift))
            {
                L |= KMod.Shift;
            }
            if (AKeys.IsPressed(KKey.LAlt))
            {
                L |= KMod.Alt;
            }
            if (AKeys.IsPressed(KKey.Win))
            {
                L |= KMod.Win;
            }
            if (AKeys.IsPressed(KKey.RCtrl))
            {
                R |= KMod.Ctrl;
            }
            if (AKeys.IsPressed(KKey.RShift))
            {
                R |= KMod.Shift;
            }
            if (AKeys.IsPressed(KKey.RAlt))
            {
                R |= KMod.Alt;
            }
            if (AKeys.IsPressed(KKey.RWin))
            {
                R |= KMod.Win;
            }
            modL = L; modR = R;
            return(L | R);
        }
Пример #7
0
    void MouseTriggers()
    {
        //examples of mouse triggers

        Triggers.Mouse[TMClick.Right, "Ctrl+Shift", TMFlags.ButtonModUp] = o => AOutput.Write(o.Trigger); //Ctrl+Shift+RightClick
        Triggers.Mouse[TMEdge.RightInCenter50] = o => {                                                   //the right edge of the primary screen, center 50%
            var m = new AMenu("example");
            m["A"] = o => {  };
            m["B"] = o => {  };
            using (m.Submenu("C")) {
                m["D"] = o => {  };
                m["E"] = o => {  };
            }
            m.Show();

            //To create menus can be used snippet menuSnippet. Start typing "menu" and you will see snippets in the completion list.
        };
        Triggers.Mouse[TMMove.LeftRightInCenter50, screen : TMScreen.Any] = o => AWnd.SwitchActiveWindow(); //move the mouse quickly to the left and back in center 50% of any screen
        Triggers.Mouse[TMMove.RightLeftInCenter50, screen : TMScreen.Any] = o => AKeys.Key("Ctrl+Tab");     //to the right and back. Ctrl+Tab should switch the active document.

        Triggers.FuncOf.NextTrigger     = o => AKeys.IsScrollLock;                                          //example of a custom scope (aka context, condition)
        Triggers.Mouse[TMWheel.Forward] = o => AOutput.Write($"{o.Trigger} while ScrollLock is on");
    }
Пример #8
0
partial class Script : AScript { [STAThread] static void Main(string[] a) => new Script(a); Script(string[] args) { //;;;

/*
The programming language is C#.

In scripts you can use classes/functions of the automation library provided by
this program, as well as of .NET Core and everything that can be used in C#.
Also you can create and use new functions, classes, libraries and .exe programs.

Script properties are saved in /*/ /*/ comments at the very start of script.
You can change them in the Properties dialog.

Like all C# programs, a script starts with standard code: using directives,
class and function Main where the program starts. Click the small [+] box at
the top-left to see and edit that code when need. The //. and //; are used to
fold (hide) code.

To avoid 'static' everywhere, function Main creates a class instance. Your script
code is in the constructor function. The function and the class end with } and }.

To run a script, you can click the ► Run button on the toolbar, or use command line,
or call ATask.Run from another scrit, or in Options set to run at startup.

Triggers such as hotkeys, autotext, mouse and window are used to execute functions
in a running script. Also you can create custom toolbars and menus. To start
using them: menu File -> New -> Examples -> @Triggers and toolbars.
*/

//Examples of automation functions.

AOutput.Write("Main script code.");

ADialog.Show("Message box.");

AExec.Run(AFolders.System + "notepad.exe");
var w = AWnd.Wait(0, true, "*- Notepad");
AKeys.Key("F5 Enter*2");
AKeys.Text(w.Name);
2.s();
w.Close();
var w2 = AWnd.Wait(-3, true, "Notepad", "#32770");
if(!w2.Is0) {
	500.ms();
	var c = +w2.Child(null, "Button", skip: 1); // "Don't Save"
	AMouse.Click(c);
	500.ms();
}

//Examples of .NET functions.

string s = "Example";
var b = new System.Text.StringBuilder();
for(int i = 0; i < s.Length; i++) {
	b.Append(s[i]).AppendLine();
}
MessageBox.Show(b.ToString());

//Example of your function and how functions can share variables.

_sharedVariable = 1;
FunctionExample("Example");
AOutput.Write(_sharedVariable);

} //end of main function