📜 ⬆️ ⬇️

Orfo Switcher History

Good day, dear chabrozhiteli!

Once a long time ago, in August of 2006, when I was a student, I was excited to write a program that would transfer the cursor keys (arrows) on the keyboard from the usual place directly to the alphabetic keyboard. The idea of ​​fix was to navigate through the editor in which I programmed without interrupting the usual position of “FYVA-OLDJ”. It was enough to hold down the Caps-Lock and I, J, K, L keys turned into cursor control keys. That was great! I had to deal with the hooks of Windows, with the peculiarity of intercepting and forging messages from the keyboard, and, despite the fact that the idea with simplified navigation did not take root even on myself (it was difficult to force myself to use the new keys), I was happy with the work done I already had everything I needed to create my own keyboard switch, which would replace the stupid (as I then thought) Punto Switcher.

At about the same time, I became acquainted with the D programming language and loved it for the opportunity to write in C ++ and at the same time enjoy automatic garbage collection, interfaces, closures and other fashionable features. It was cool! I decided to rewrite the keyboard interceptor on D, adding to it so that it switches the keyboard layout, if I started typing, forgetting to switch the language. I didn’t just switch, but erased the abracadabra that I had already typed and inserted the corrected text. Well, you all know how Punto does it.
')
And after a while everything was ready. I had a file in which combinations of characters were listed through the line break symbol, upon meeting which, the program automatically switched the layout. After listening to Sergey Moskalev (the author of Punto) on the radio, I decided that the secret of the success of the correct switching lies in the "impossibilities" of the language, which he said he had accumulated with him while he was working on combing the recognition result of the scanned text pages. Well, you all know this story .

I tried to figure out the impossibility vocabulary from the Punto distribution, but nothing came of it. It was not possible to figure out the format of the ps.dat file, and it seemed to me to compile statistics of impossible combinations of characters, processing text volumes by some incomplete method that will always strive for perfection, but will never reach it. And I decided to go another way - to include absolutely all the words of the language in the program. It seemed to be the solution to all problems! At that moment I decided that the program would still spell check if it already contained all the words in the correct form.

Downloading from a site a list of all Russian words with all possible endings and prefixes, I found that there are much more of them than I expected - about 800,000 words! The Russian language file weighed about 15 megabytes, and the search for the word in it took tens of milliseconds! It was no good, because in order to find a similar word, you need to do more than a hundred search operations and these milliseconds would turn into seconds, and no one wants to wait a second until a menu appears with the correct version of the word. It was close to failure.

A little later, I discovered that I was lucky, because most of the words of the Russian language are a continuation of some other, already existing word. That was great news!

If you place all the words in the form of a special tree, in which the root nodes are letters of the alphabet on which words can begin, the second level nodes are letters that can be in second position in words and so on until the very last letter of the longest word, you can not only reduce the size of the dictionary file several times, but also create ideal conditions for the search, because each node contains the size of the entire branch, and if the node letter does not match the desired word, we can step over the entire branch without needing to ebora all its contents. So I did. It turned out a great dictionary! Any number of iterations of the search took about 0 milliseconds of time, and my hands were finally completely untied. The size of the Russian dictionary was only 5 mb, and the English one 1.4 mb. In the archive, both dictionaries, together with the orfoswitcher.exe executable, occupied only 1.1 megabytes. Great size for such a program. I was very pleased with the work!

Having this, it was very easy to come up with an algorithm for switching layouts. It was enough to look whether the dialed combination exists in one dictionary and whether it does not exist in another. If this is the case and the layout does not match the found word, then the switch is made. It worked fine, and all the wrong switches were solved by adding some new word to the dictionary. It immediately became clear, for example, that the word “schA” constantly switches to the English “of”, and, despite the dictionary of eight hundred thousand words, it had to be manually added with such popular words.

The next interesting task was to create a menu that could work in any application. Supposedly correct spellings of words should have appeared in this menu, and perhaps something else. I already knew how to integrate into running applications using Windows hooks, but there were problems with the menu. The first attempts were unsuccessful. Creating a standard Windows menu from the active application space did not always work - some applications hung and behaved unpredictably, because each application has its own principle of operation, and there were no guarantees that the menu would be processed correctly and messages from it would successfully fall into the loop of the program's messages. Creating the menu from the orfoswitcher process led to a loss of focus for the current application, which was also ugly. After all, even if I return the focus after displaying the menu back to the active application, there are no guarantees that the application will not do any work on removing or setting the focus. Any solution was either unstable or did not work everywhere.

Once again I was lucky. When I looked at Spy ++ using the On-Screen Keyboard application (osk.exe), I found that the Windows creators had provided a special window style called WS_EX_NOACTIVATE, thanks to which the created window never becomes active, even if you click on it with the mouse. It was wonderful, because on the basis of this window I was able to make a menu that could be accessed using both the mouse and the keyboard, while the input cursor remained in the current application. This menu was ideal for displaying the correct words in a spell checker, but I understood that it could have other useful uses.

The first application that came to mind is to save the history of everything that was copied and display the display as menu items. One item for each text clip on the clipboard. This is how the clipboard history appeared in the program. It turned out to be convenient to always have at hand the last pieces of text, especially when it was necessary to copy the login from somewhere, then the password, and then paste them into the input fields. It was possible not to worry that the clipboard would be overwritten with new copied text, because everything in history remained, even after turning off the computer. A friend told me that the clipboard history is the only function of the orbiter that stops it before removing the program. I have always appreciated his frankness.

Then there were notes in the program, the autochange function, all sorts of exceptions to work in applications, and the orbit switch gradually came to the form in which you can see it now. Such is the story. I hope someone also came in handy this program.

Software website: virtassist.eu

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


All Articles