Mein Fahrrad oder wie ich meine Nervenzellen gerettet habe

    Grüße an die Bürger von Khabrovsk!

    Es ist ein halbes Jahr vergangen, seit mein Haupt-Desktop unter Ubuntu läuft. Ich werde nicht über die Vor- und Nachteile von Linux schreiben. In diesem Beitrag geht es nicht darum.
    Also ... ich habe leider keine blinde Schreibmethode, und es hat keinen Sinn gemacht zu lernen, weil das Windows-PuntoSwitcher-Programm, das ich für ungefähr 5 Jahre verwendete, mich ziemlich erträglich rettete, aber sein Xneur-Gegenstück auf Ubuntu, gelinde gesagt, nicht sehr gut funktionierte und funktionierte überhaupt nicht mit Skype.

    Ich habe das eine Weile ertragen und dann erfolglos versucht, ein kleines Programm in Java zu schreiben.

    Programmanforderungen:

    1. Schnellstart
    2. Symbol in der Taskleiste, um die Anwendung zu beenden und die Konvertierung abzubrechen
    3. Globale Verknüpfungskonvertierung


    - Dies ist die Funktionalität, die ich in PuntoSwitcher verwendet habe.

    Bild


    Und buchstäblich heute Abend habe ich beschlossen, den anderen Weg zu gehen und sh zu benutzen.

    Ich gebe nicht vor, universell zu sein, aber auf Kubuntu 15.10 funktioniert es so, wie es sollte.

    Arbeitsprinzip:

    1. Eine Verknüpfung wird an die sh-Verknüpfung des Skripts angehängt
    2. Nachdem wir mit xclip begonnen haben, erhalten wir den ausgewählten Text
    3. Konvertieren Sie es in das entgegengesetzte Layout
    4. Fügen Sie mit dem Dienstprogramm xdotool den neuen Text anstelle des ausgewählten ein
    5. Wir ändern das Layout in das Gegenteil, um mit der Eingabe fortzufahren.


    Von Worten zu Taten:
     #!/bin/bash 
    oldtemp=`xclip -o` #скопировали текст
    temp=`'/home/username/desktop/switch' "$oldtemp"` #конвертируем текст
    xdotool keydown Shift+Control_L #сменили раскладку
    sleep 1 
    xdotool keyup Shift+Control_L
    xdotool type "$temp" #печатаем новый текст
    notify-send "$oldtemp
    ->
    $temp" -t 2000 #сообщение о том что сменили раскладку (опционально)
    exit 0
    


    xdotool keydown / xdotool keyup wird anstelle von xdotool key verwendet, da letzteres bei mir einmal funktioniert hat.

    Nun zur Textkonvertierung.
    Zu diesem Zweck entschied ich mich für ein separates Programm in C ++, das Text empfängt, versteht, wie er konvertiert werden soll, und bereits normalen Text an die Konsole sendet.

    Vorher musste ich nicht in C ++ schreiben, da die Funktionalität dieses Dienstprogramms auf der Ebene von "Hello World" liegt.

    Schwangere Kinder mit einer schwachen Mentalität schauen nicht zu
    #include 
    using namespace std;
    std::string Toreplace(std::string text, std::string s, std::string d){
        for(int index=0; index=text.find(s, index), index!=std::string::npos;)    {
            text.replace(index, s.length(), d);
            index+=d.length();
        }
        return text;
    }
    int GetCurentLang(std::string str){
        int thislang = 0;
        const char *cstr = str.c_str();
        std::string russtr[66] = {"й","ц","у","к","е","н","г","ш","щ","з","х","ъ","ф","ы","в","а","п","р","о","л","д","ж","э","я","ч","с","м","и","т","ь","б","ю","ё","Й","Ц","У","К","Е","Н","Г","Ш","Щ","З","Х","Ъ","Ф","Ы","В","А","П","Р","О","Л","Д","Ж","Э","Я","Ч","С","М","И","Т","Ь","Б","Ю","Ё"};
        std::string engstr[56] =  {"q","w","e","r","t","y","u","i","o","p","[","]","a","s","d","f","g","h","j","k","l","z","x","c","v","b","n","m","<",">","Q","W","E","R","T","Y","U","I","O","P","A","S","D","F","G","H","J","K","L","Z","X","C","V","B","N","M"};
        for (int i = 0; i < str.length() && thislang == 0; i++){
            for (int a = 0; a < 66; a++){
                if (russtr[a].compare(new char (cstr[i])) == true) {
                    thislang = 1;
                }
            }
            for (int a = 0; a < 56; a++){
                if (engstr[a].compare(new char (cstr[i])) == true) {
                    thislang = 2;
                }
            }
        }
        return thislang;
    }
    std::string TranslateToRu(std::string str){
        std::string translate = str;
        std::string replacein[67] = {"q","w","e","r","t","y","u","i","o","p","[","]","a","s","d","f","g","h","j","k","l",";","'","z","x","c","v","b","n","m",",",".","/","Q","W","E","R","T","Y","U","I","O","P","[","]","A","S","D","F","G","H","J","K","L",";","'","Z","X","C","V","B","N","M",",",".","/","&"};
        std::string replaceto[67] = {"й","ц","у","к","е","н","г","ш","щ","з","х","ъ","ф","ы","в","а","п","р","о","л","д","ж","э","я","ч","с","м","и","т","ь","б","ю",".","Й","Ц","У","К","Е","Н","Г","Ш","Щ","З","Х","Ъ","Ф","Ы","В","А","П","Р","О","Л","Д","Ж","Э","Я","Ч","С","М","И","Т","Ь","Б","Ю",".","?"};
        for (int i = 0; i < 67; i++){
            translate = Toreplace(translate, replacein[i], replaceto[i]);
        }
        return translate;
    }
    std::string TranslateToEng(std::string str){
        std::string translate = str;
        std::string replacein[67] = {"й","ц","у","к","е","н","г","ш","щ","з","х","ъ","ф","ы","в","а","п","р","о","л","д","ж","э","я","ч","с","м","и","т","ь","б","ю",".","Й","Ц","У","К","Е","Н","Г","Ш","Щ","З","Х","Ъ","Ф","Ы","В","А","П","Р","О","Л","Д","Ж","Э","Я","Ч","С","М","И","Т","Ь","Б","Ю",".","?"};
        std::string replaceto[67] = {"q","w","e","r","t","y","u","i","o","p","[","]","a","s","d","f","g","h","j","k","l",";","'","z","x","c","v","b","n","m",",",".","/","Q","W","E","R","T","Y","U","I","O","P","[","]","A","S","D","F","G","H","J","K","L",";","'","Z","X","C","V","B","N","M","<",">","/","&"};
        for (int i = 0; i < 67; i++){
            translate = Toreplace(translate, replacein[i], replaceto[i]);
        }
        return translate;
    }
    int main(int argc, char *argv[]) {
        std::string translate;
        int currentlang = GetCurentLang(argv[1]);
        if (currentlang == 2){
            translate = TranslateToRu(argv[1]);
        }else if (currentlang == 1){
            translate = TranslateToEng(argv[1]);
        }else{
            translate = "";
        }
        cout << translate << endl;
        return 0;
    }
    



    GetCurentLang Akzeptiert den gesamten Text und sucht nach dem ersten Zeichen im russischen oder englischen Layout. Wenn das erste Zeichen im englischen Layout bedeutet, dass Sie alles ins Russische übersetzen müssen (wir ignorieren natürlich die Zeichen),

    TranslateToEng , TranslateToRu, ein Array mit Buchstaben für jede Richtung, um in Zukunft Ihr eigenes zu konfigurieren Der Austausch ist flexibler.

    warum std :: string statt char [] - wie gesagt C ++ nicht kennt, und in dem char [] nicht paßt ... Kyrillisch (oder so ähnlich)

    Während Umwandlung in eine Richtung geht, das heißt, wenn Schreiben Sie: Am Ausgang erhalten wir:
    Бвшм шв=ЭьфштЭЮdjnБ.вшмЮ




    djn


    Es wäre ratsam, auch "djn" umzuwandeln, aber dann stellt sich die Frage, ob die Zeichen ",. /" usw. falsch definiert sind. Außerdem wird der mit
    Strg + A hervorgehobene Text nicht in xclip übernommen. Vielleicht sollten Sie stattdessen Folgendes verwenden:

    xdotool keyup Control_L+С
    

    Jetzt auch beliebt: