📜 ⬆️ ⬇️

Mahou - Magic Layout Switch

How I created the first function


It all started when I wanted to program in C # (before creating this program, I had almost no knowledge of C #), and there was one program that didn’t work as I wanted (Punto Switcher) for a long time I was looking for alternatives to it and I stopped at dotSwitcher for a while I liked it ... But after a while I decided that it lacked functionality and decided to look at the source code, I somehow figured out how everything works, but most of all I didn't understand one thing - WinAPI, and I started look for information on the functions used in dotSwitcher and little by little I start cash to memorize and understand the meaning of all this magic (so it seemed to me).


I didn't want to write to the already created dotSwitcher. there is a completely different style of coding, and besides, I would not understand why this or that function or variable, so I decided to create everything from scratch ! For a start, I dealt with the HOOKs, then with the PostMessage function with the help of which I was able to change the layout, due to which I already had ideas about how it would be possible to convert the typed text. I created a list of keys into which all globally pressed keys fell (thanks to the keyboard HOOK) attached cleaning the list of keys by mouse clicks (thanks to the mouse HOOK) and created a hot key on which the layout changed, but the question remained "How to make the program enter These keys? ", then I found out about the SendInput and keybd_event functions that did just that. After I redid the hotkey function on:


  1. Change the layout.
  2. Send backspace [number of keys caught] times.
  3. Enter [captured keys].

And she worked !!! As I wanted.


Each function needs its own way of implementation, here I described how I created the first function to change the layout of the last typed text.


Regarding the name, I called the program (in Japanese, because I really like it) - 魔法 (Mahou), which in Japanese means "Magic", "Magic" - C #, WinAPI and my brain (coming up with ways to implement the functions) is There is that magic that is hidden in the title.


This is how the first window of Mahou looked:



This is what the main window looks like now:



It even works on Windows XP SP3!



Description


.Net 4.5, .Net 4.0 . WinAPI HOOK' . .Net, buildMahou.cmd. Open Source GPL v2. , Wiki. . Mahou Chocolatey, cinst Mahou -y.


:



:


, / ( ):



:


GitHub
GitHub
Wiki GitHub
GitHub


')

Source: https://habr.com/ru/post/321518/


All Articles