butterfly
butterfly

Reputation: 93

change keyboard language by API in vb.net

I'm new to vb.net and I'm supposed to change the keyboard language to Farsi(Persian) by using API functions while the program is running( It's a plain form with a text box). Does anybody know what should I do? Any kind of help would be greatly appreciated.

Upvotes: 4

Views: 6005

Answers (4)

supwat
supwat

Reputation: 11

I created a prog which send character to another app by using command My.Computer.Keyboard.SendKeys("en-US text", True) but sometime current input language is not en-US then all character sending are incorrect. After study from Ezi word, I was solved by modify something like these: Thanks to Ezi.

Private Sub ipl(lg As String)
    Dim TypeOfLanguage = New System.Globalization.CultureInfo(lg) ' or "fa-IR" for Farsi(Iran) 
    InputLanguage.CurrentInputLanguage = InputLanguage.FromCulture(TypeOfLanguage)
End Sub

Private Sub swlg() 'switch language TH-US
    If InputLanguage.CurrentInputLanguage.Culture.Name <> "en-US" Then
        Do
            ipl("en-US")
        Loop Until InputLanguage.CurrentInputLanguage.Culture.Name = "en-US"
    End If
End Sub

Upvotes: 0

Werner Keil
Werner Keil

Reputation: 642

Would be nice, but InputLanguage does not seem to work with WPF. InputLanguage is a Windows Forms type.

Upvotes: 0

w3soultech
w3soultech

Reputation: 1

Dim TypeOfLanguage = New System.Globalization.CultureInfo("fa") ' or "fa-IR" for Farsi(Iran) 
InputLanguage.CurrentInputLanguage = InputLanguage.FromCulture(TypeOfLanguage)

This is working fine without the need to use any APIs.

Upvotes: 0

Ezi
Ezi

Reputation: 2210

Its very easy. no need to use api its build in to the .net framework.

Dim TypeOfLanguage = New System.Globalization.CultureInfo("fa") ' or "fa-IR" for Farsi(Iran) 
InputLanguage.CurrentInputLanguage = InputLanguage.FromCulture(TypeOfLanguage)

More info on localization..

Upvotes: 4

Related Questions