AHK at the minimum. Binder

Idea


Hey. I am a beginner C # .NET developer (as a second year beginner). I was tired of writing all sorts of calculators, etc., so I asked myself: “What am I missing in Windows?”. And the answer that I came to gave me the idea: “Everything.” So there was Binder, a project that allowed me to learn a lot about C #, .NET and WPF, and gave me some good software that I liked so much that I decided to show it to everyone.

About the program itself


Binder is intended, unexpectedly, for binds. These binds can be configured for any key combination: button + 2 modifiers (CTRL, Shift, ALt, Win), as well as stick scripts on them. The script is written in an internal language, which I tried to make as similar as possible to C #.
The principle is the same as in AutoHotKey. The program comes with a DLL, into which I slowly add various functions (there are 49 of them now). In my opinion, the Binder language can already be considered an interpreted programming language, albeit little capable, because there is already an if-else construct, while and repeat loops, functions (asynchronous too), break and return statements, int, double, bool, string data types.

In the program, the binders work globally throughout the PC, and the key simulation taken from AHK can simulate keystrokes in almost all applications.

The first task I wanted to solve with Binder was to show / hide desktop icons. And so the first script I added is ShowHideDesktopIcons (bool show). But here the question arises, how to make both hide and show with one button? I decided it by adding the “Bind switch” parameter to the binders, which allows you to hang 2 scripts on 1 bind at once, which are executed in turn. Already now on Binder you can make an autoclicker, or for example, a bind, Ctrl + Shift + C, which will add the selected text to the clipboard, and not replace it, or a bind to turn off / restart the PC. One of the most useful is the “Super Alt + F4” bind, which receives the active window process and kills it. The program has support for variables: You can save any value using SetVar (), and get it GetVar (). Today with made attributes to execute scripts,and the first was Block, which blocks the keystroke of the bind until its main thread is completed. In the near future, it is planned to add namespaces to transfer variables from one script to another.

A useful addition, I think, is the Record function, which records all actions from the keyboard and mouse, immediately turning them into a script for Binder.

In the help window you can find all the available functions, and soon there will appear attributes for scripts.

All binds can be saved to a file so as not to lose.

In the settings you can enable the launch of the program with Windows, configure the default bind file to be opened.



I want to note a convenient thing: when using nested constructions (for example, if inside the while), after clicking the "Save" button, the script will be formatted beautifully.

Syntax


In Binder, the syntax familiar to all programmers was made in the likeness of C #.

For example, a call to the MsgBox function (like any other) looks like this:

MsgBox(" ", "    ");

When this line is executed, the result will be as follows:



MsgBox () accepts the parameters, you can see them for each function in the help window.

To help, all functions are sorted by the type of return value:



Anyone who wrote in C ++ / C # will immediately understand how this works, except for the first type: functions from the "Non-Returning Values" group return the parameters passed to them.
For instance:

MsgBox(MsgBox("Hello"));

2 times will display a message with the text "Hello".

From this line, one more important detail can be understood: some functions can be transferred to parameters by others.

In addition to the built-in functions, the program has various designs. It should be noted that I have any whole structure considered as 1 team, so at the end of each of them you need to put;. I will remove it later.

If-else construct.


It works just like in any other language:

if(<1>)
{
<1>
}
else if(<2>)
{
<2>
}
....
else
{<,    false>};

You can write as much else if you want, write / not write else, in general, as you like. The main thing is that in parentheses <condition> should be of type Boolean. For example, you can write true there, and the condition will always be satisfied.

Repeat construct


repeat is the simplest loop in the program, there must be an Int value in parentheses, and it simply repeats the action the specified number of times, for example:

repeat(SumInt(2,3))
{
    MsgBox("");
};

5 times displays the message "Hello."

It has 2 modifications:

1) async repeat (). A separate thread will be allocated for its execution, i.e. immediately after its beginning, the functions after it will be executed.

2) allasync repeat () will immediately start executing the code inside itself the specified number of times, for example:

allasync repeat(5)
{
    MsgBox("Hello");
};

At the same time it will display 5 messages:



While construct


While - literally from English. - while the condition is true. Performs functions within itself as long as the condition is true in parentheses. This condition must be of type Boolean.

You can forcefully abort loop execution using the break statement; Example:

SetVar("i", 0);
while(true)
{
    SetVar("i", SumInt(GetVar("i"), 1));
    MsgBox(GetVar("i"));
    if(MoreThan(GetVar("i"), 10))
    {
        break;
    };
    
};
MsgBox("");

Print messages with numbers from 1 to 11, and exit.

While also has a modification of async while, which simply executes it in a separate thread, allowing you to continue executing the main code.

Functions


In Binder, you can declare and use your functions and pass parameters to them

func f1(text)
{
MsgBox(ReplaceString(text, "\", " habr "));
};
f1(GetDesktopPath());

My output:



Also functions can return values, for this you need to use the return statement:

func f1(text)
{
    return MsgBox(ReplaceString(text, "\", " habr "));
};
MsgBox(f1(GetDesktopPath()));

Now the same result, only the message is displayed 2 times.

About the group


Thus, you can create anything based on Binder, you only need functions in the library, which I can add very simply, for this I need only ideas. This is one of the reasons for creating the VKontakte group vk.com/public192980751 . Binder is absolutely free, and I am ready to help with any question about the program. Please support me by simply advising what to add, by testing the project, or simply by subscribing to the group.

PS The project appeared on GitHub github.com/Electrominch/Binder

All Articles