Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsVB SyntaxEnterprise DevelopmentDatabase AccessControlsCOMWin APICrystal ReportDeploymentGeneralGeneral 2
Related Topics
VB.NET / ASP.NETMS SQL ServerMS AccessOther Database ProductsMore Topics ...

VB Forum / Database Access / October 2008



Tip: Looking for answers? Try searching our database.

How can I switch keyboard language from VB code.

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Yuvigi - 14 Mar 2007 13:01 GMT
I am writing an MS Access application. Text in some controls on forms must be
typed in Cyrillic, in others - in English. How can I change keyboard language
from code upon entering certain control?
Richard T. Edwards - 25 Mar 2007 00:39 GMT
You might want to try using WMI.

>I am writing an MS Access application. Text in some controls on forms must
>be
> typed in Cyrillic, in others - in English. How can I change keyboard
> language
> from code upon entering certain control?
Yuvigi - 08 Apr 2007 06:14 GMT
Thanks Richard!

I have already solved my problem. It took some further reading but I
eventually achieved it.

Thanks and best regards,

Rado Christov (Yuvigi)
:)

> You might want to try using WMI.
>
[quoted text clipped - 3 lines]
> > language
> > from code upon entering certain control?
Max Kudrenko - 26 Mar 2007 12:47 GMT
Yuvigi,

Check the ActivateKeyboardLayout function. Here's a good example of
its use at the bottom: http://allapi.mentalis.org/apilist/ActivateKeyboardLayout.shtml

Hope this helps,

Max Kudrenko
Brainbench MVP Program for Visual Basic
www.brainbench.com

> I am writing an MS Access application. Text in some controls on forms must be
> typed in Cyrillic, in others - in English. How can I change keyboard language
> from code upon entering certain control?
Yuvigi - 08 Apr 2007 05:56 GMT
Thanks Max.

Although I had already solved my problem, the information on the site in
your post was pretty helpful as it contained most of the information needed
to write a procedure to do the job. Thanks and good luck.

Best regards,
Rado Christov (Yuvigi)
:)

> Yuvigi,
>
[quoted text clipped - 10 lines]
> > typed in Cyrillic, in others - in English. How can I change keyboard language
> > from code upon entering certain control?
DesignStudio - 08 Sep 2008 09:45 GMT
Dear Yuvigi,
Could you please share with us how you solved your problem?

> Thanks Max.
>
[quoted text clipped - 20 lines]
> > > typed in Cyrillic, in others - in English. How can I change keyboard language
> > > from code upon entering certain control?
Yuvigi - 19 Sep 2008 21:43 GMT
Dear DesignStudio,

It's pretty easy once you've grasped the logic. The bulk of time wasted is
to namely understand the logic. The rest is simple.

Here is a little function I wrote, which can be called from any event in my
programme. It changes the keyboard layout to the desired one, provided it is
installed. If the desired layout has not been installed, the function
displays a message to the user.

I use this code in a MSAccess application. It utilises a table called
"Locales" that stores information about different locales and languages.
Below is and excerp from the table:

LCID       Locale                          Language        LCName  Tag    
CP_ANSI     acPLID

&H0402  Bulgarian (Bulgaria)       Bulgarian        bg-BG   Cyrl     1251    
   4
&H0407  German (Germany)        German          de-DE   Latn    1252        9
&H0409  English (United States)   English           en-US   Latn    1252    
  11

And here is the code:

Public Function Lang_Keyboard_Change(Optional ByVal sArg As String =
"&H0409", _
                                       Optional ByVal sArgType As String =
"LCID" _
                                       ) As Boolean
   
   'This function changes the keyboard language to the desired one.
   'It assumes that the system default language is English(Primary language
code = 0x09.
   'and that its hex code is passed by default.
   'If another locale argument's value is passed as an argument, then
   'the function looks up the LCID value in the Locales table.
   'If the language is installed, its layout is activated.
   'Else a message is displayed to the user and current language
   'layout is kept.
   
   Dim sA As String, sB As String, sC As String
   Dim lA As Long, lB As Long, lC As Long
   
   On Error GoTo Err_1
   
   If sArgType = "LCID" Then
       lB = Val(Replace(sArg, "0x", "&H"))
   Else
       sA = sArgType & "='" & sArg & "'"
       sB = Nz(DLookup("LCID", "Locales", sA))
       If sB = "" Then
           'Unsupported or wrong locale.
'            MsgBox SM(6571) & vbCr & sArgType & "='" & sArg & "'"
           MsgBox "Wrong or unsupported regional settings." & vbCr _
               & sArgType & "='" & sArg & "'"
           Exit Function
       End If
       sB = Replace(sB, "0x", "&H")
       lB = Val(sB)
   End If
   
   'Extract language code and save it to a variable.
   lB = lB And &HFFFF&
   
   'lB is the Target KB value.
   
   If lB = 0 Then
       'Target KB Language is the system language, so go to true exit.
       GoTo Exit_True
   End If
   
   'Get initial/current layout name.
   lA = GetKeyboardLayout(0)
   
   'Exit if GetKeyboardLayout function failed.
   If lA = 0 Then
       Exit Function
   End If

   'Extract language code and save it to a variable.
   lA = lA And &HFFFF&
   
   'lA is the Initial KB value.
   
   'Check if this is the desired language code.
   If lA = lB Then
       'Language is the same, so go to true exit.
       GoTo Exit_True
   End If
   
   'Activate the previous keyboard layout.
   lC = ActivateKeyboardLayout(HKL_PREV, KLF_ACTIVATE)
   'Get layout.
   lC = GetKeyboardLayout(0)
   'Extract language code.
   lC = lC And &HFFFF&
   
   'Loop through installed keyboard layouts
   'until the desired language is loaded or
   'loop completes a full cycle.
   Do
       If lC = lB Then
           'This is the needed language, so exit
                       'loop and go to true exit.
           GoTo Exit_True
       End If
       
       'Activate the previous keyboard layout.
       lC = ActivateKeyboardLayout(HKL_PREV, KLF_ACTIVATE)
       'Get layout.
       lC = GetKeyboardLayout(0)
       'Extract language code.
       lC = lC And &HFFFF&
   Loop While lC <> lA
   
   'The desired keyboard layout is not installed on the system.
   'Display a message to the user.
   If sArgType = "LCID" Then
       sA = sArgType & "='" & Replace(sArg, "0x", "&H") & "'"
   Else
       sA = sArgType & "='" & sArg & "'"
   End If
   sB = Nz(DLookup("Locale", "Locales", sA))
   MsgBox sB & vbCrLf & "The desired keyboard layout is not installed on
the system." _
           & "Install it first from Control Panel > " _
           & "Regional and Language Options.", vbInformation, sAppTitle
Exit_False:
   Exit Function
   
Exit_True:
   Lang_Keyboard_Change = True

Exit_1:
   Exit Function
   
Err_1:
   MsgBox Err.Description, vbExclamation, sAppTitle
   Resume Exit_1
   
End Function

I hope you find this post usefull. It works fine for me.
Good luck.
Best wishes from Bulgaria!

> Dear Yuvigi,
> Could you please share with us how you solved your problem?
[quoted text clipped - 23 lines]
> > > > typed in Cyrillic, in others - in English. How can I change keyboard language
> > > > from code upon entering certain control?
DesignStudio - 20 Sep 2008 09:44 GMT
Dear Yuvigi,

Thanks for your help. I'll try that and let you know if it didn't work.

By the way I am a scuba diver and I have read about the Bulgarian Black Sea
coast. I really would love to dive there in the future.
This is my email  tarak100@hotmail.com.

Thanks a lot.

> Dear DesignStudio,
>
[quoted text clipped - 170 lines]
> > > > > typed in Cyrillic, in others - in English. How can I change keyboard language
> > > > > from code upon entering certain control?
Yuvigi - 31 Oct 2008 21:34 GMT
Hello "DesignStudio",

Although I live by the sea I've only dived once in my life. It was a very
enjoyable experience, I decompressed alright and everything but for the next
couple of months I had problems with my right ear. So I stick to swimming on
the surface :)
My e-mail is yuvigi@hotmail.com and you're welcome to BG any time.

Best regards

> Dear Yuvigi,
>
[quoted text clipped - 180 lines]
> > > > > > typed in Cyrillic, in others - in English. How can I change keyboard language
> > > > > > from code upon entering certain control?
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.