Jump to content

Many can not blind-type. This is problem for dual keyboard layouts users. This script solves this for English/Hebrew


IlanMS
 Share

Recommended Posts

This is far from being polished, but so far it worked well, and I doubt I'll polish it further. If I will I ill edit and update.

 

The user selects the phrase he typed with the wrong keyboard layout and presses Pause/Break to convert the text from English to Hebrew or vice versa. The script determines which way to convert by checking what language are the majority of characters.

Conversion examples:

hunhho anhho udao ckh nho is converted to יומיים שמיים וגשם בלי מים
Sם 'ישא,ד מק'ת Gקםרעק? is converted to So whats new, George?

;המרה TO DO Enable user to change the hotkey. Use MIDI instead of .wav? Handle possible errors? Add switching keyboard layout via Scroll Lock? More coherent functions and variables names?
#include <Constants.au3>
#include <Array.au3>
;SoundPlay(@WindowsDir & "\media\Alarm10.wav",1)
HotKeySet("{PAUSE}", "Main")
While 1 ;loop until keypressed
Sleep(100) ;Don't kill the CPU
WEnd
Sleep(100)

Func Main() ;TO DO play a nice and short midi sound, include Midiudf.au3
    SoundPlay(@WindowsDir & "\media\Speech On.wav",1) ;להשמיע צליל על מנת שנדע שההמרה בשלבי ביצוע
    $hWnd= WinGetHandle("[active]")
        $CopiedText=_GetTextFromActiveWindow($hWnd)
    ;MsgBox ( 0, "In MAIN", $CopiedText)
    If _CheckEng2HebOrHebToEng($CopiedText) > 0 then
        $Result = _HandleH2E ($CopiedText)
    Else
        $Result = _HandleE2H ($CopiedText)
    EndIf
    ClipPut($Result)
    WinActivate ($hWnd)
    Send("^v")
EndFunc

Func _GetTextFromActiveWindow($hWnd) ;Taken as is נראה שיש פה מה לגזום אבל זה לא חשוב
    ClipPut("") ;ניקוי קליפבורד
    $readtext = "" ;Clipboard data goes to this
    For $i = 1 to 8 Step 1
        $rand = random (1, 4, 1)
        Send ("{CTRLDOWN}")
        Switch $rand  ;Try various methods until we get text on the clipboard
            Case 1
                Send("{INS}") 
            Case 2
                ControlSend($hWnd, "", "", "{INS}")
            Case 3
                Send("c")
            Case 4
                ControlSend($hWnd, "", "", "c^")
        EndSwitch
        Send ("{CTRLUP}")
        $readtext = ClipGet() ;Any text on the clipboard?
        If $readtext <> "" Then
            return $readtext
        EndIf
        If $i = 4 Then
            WinActivate($hWnd)
            Sleep(100)
        EndIf
    Next
    return $readtext
EndFunc

Func _HandleE2H($CopiedText) ;המרת הקלדה באנגלית לעברית
     $CharsCount = StringLen($CopiedText)
     ;MsgBox(0, "", $CharsCount)
     $CharsArray = StringSplit($CopiedText, "")
     $OutputText = ""
     For $i = 1 to $CharsCount
        $Isolated = $CharsArray[$i]
        $ConvertedChar = _CharConvE2H($Isolated)
        ;MsgBox(0, "", $Isolated &" " &$ConvertedChar)
        $OutputText = $OutputText & $ConvertedChar
    Next
    ;MsgBox(0, "אנגלית לעברית", $OutputText)
    Return $OutputText
EndFunc

Func _HandleH2E($CopiedText) ;המרת הקלדה בעברית לאנגלית
     $CharsCount = StringLen($CopiedText)
     ;MsgBox(0, "_HandleH2E", $CharsCount)
     $CharsArray = StringSplit($CopiedText, "")
     $OutputText = ""
     For $i = 1 to $CharsCount
        $Isolated = $CharsArray[$i]
        $ConvertedChar = _CharConvH2E($Isolated)
        ;MsgBox(0, "_HandleH2E", $Isolated &" Converted to " &$ConvertedChar)
        $OutputText = $OutputText & $ConvertedChar
    Next
    Return $OutputText
EndFunc

;טבלת המרה הקלדה אנגלית לעברית conversion table. TO DO: order the 10 top entries to cover most freqently used letters.
Func _CharConvE2H($CharIn)
    Switch $CharIn
        Case 'q' , 'Q'
            Return "/"
        Case 'w' , 'W' 
            Return ""
        Case 'e' , 'E' 
            Return "ק"
        Case 'r' , 'R' 
            Return "ר"
        Case 't' , 'T' 
            Return "א"
        Case 'y' , 'Y' 
            Return "ט"
        Case 'u' , 'U' 
            Return "ו"
        Case 'i' , 'I' 
            Return "ן"
        Case 'o' , 'O' 
            Return "ם"
        Case 'p' , 'P' 
            Return "פ"
        Case 'a' , 'A' 
            Return "ש"
        Case 's' , 'S' 
            Return "ד"
        Case 'd' , 'D' 
            Return "ג"
        Case 'f' , 'F' 
            Return "כ"
        Case 'g' , 'G' 
            Return "ע"
        Case 'h' , 'H' 
            Return "י"
        Case 'j' , 'J' 
            Return "ח"
        Case 'k' , 'K' 
            Return "ל"
        Case 'l' , 'L' 
            Return "ך"
        Case ';' , ';' 
            Return "ף"
        Case 'z' , 'Z' 
            Return "ז"
        Case 'x' , 'X' 
            Return "ס"
        Case 'c' , 'C' 
            Return "ב"
        Case 'v' , 'V' 
            Return "ה"
        Case 'b' , 'B' 
            Return "נ"
        Case 'n' , 'N' 
            Return "מ"
        Case 'm' , 'M' 
            Return "צ"
        Case ',' , '<' 
            Return "ת"
        Case '.' , '>' 
            Return "ץ"
        Case '/'
            Return "."
        Case Else
            Return $CharIn
    EndSwitch
EndFunc

Func _CharConvH2E($CharIn) ;טבלת המרה הקלדה עברית לאנגלית
; טיפול באותיות הסופיות CASE  לא מבדיל בינהן לרגילות
    If $CharIn=='ם' Then
        Return 'o'
    EndIf
    If $CharIn=='ן' Then
        Return 'i'
    EndIf
    If $CharIn=='ך' Then
        Return 'l'
    EndIf
    If $CharIn=='ף' Then
        Return ';'
    EndIf
    If $CharIn=='ץ' Then
        Return '.'
    EndIf
    If $CharIn=="'" Then
        Return 'w'
    EndIf
;עד כאן טיפול בסופיות
    Switch $CharIn
        Case '/'
            Return "q"
;       Case '''
            Return "w"
        Case 'ק'
            Return "e"
        Case 'ר'
            Return "r"
        Case 'א'
            Return "t"
        Case 'ט'
            Return "y"
        Case 'ו'
            Return "u"
        Case 'פ'
            Return "p"
        Case 'ש'
            Return "a"
        Case 'ד'
            Return "s"
        Case 'ג'
            Return "d"
        Case 'כ'
            Return "f"
        Case 'ע'
            Return "g"
        Case 'י'
            Return "h"
        Case 'ח'
            Return "j"
        Case 'ל'
            Return "k"
        Case ','
            Return ""
        Case 'ז'
            Return "z"
        Case 'ס'
            Return "x"
        Case 'ב'
            Return "c"
        Case 'ה'
            Return "v"
        Case 'נ'
            Return "b"
        Case 'מ'
            Return "n"
        Case 'צ'
            Return "m"
        Case 'ת'
            Return ","
        Case Else
            Return $CharIn
    EndSwitch
EndFunc

Func _CheckEng2HebOrHebToEng($CopiedText) ;להחליט אם להמיר לעברית או לאנגלית על פי "הרוב קובע"
    $CharsCount = StringLen($CopiedText)
    ;MsgBox(0, "", $CharsCount)
    $CharsArray = StringSplit($CopiedText, "")
    $Output = 0
    For $i = 1 to $CharsCount
        $Output = $Output + _TestWhichLangChar($CharsArray[$i])
    Next
    ;MsgBox(0, "In _CheckEng2HebOrHebToEng", $Output)
    Return $Output
EndFunc

Func _TestWhichLangChar($CharIn) ;בדיקה האם אות היא בעברית או באנגלית
    ;MsgBox (0, "Input is", $CharIn)
    Switch $CharIn
        Case "א" To "ת"
            Return 1
        Case "a" to "z", "A" to "Z"
            Return -1
        Case Else
            Return 0
    EndSwitch
EndFunc

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...