none
Any idea how to change system keyboard language with vba RRS feed

  • Question

  • Any idea how to change system keyboard language with vba

    I tried changing keyboard property in the control property and it works

    but i need change in one control only, and if i change property it change for all contols after
    so i need code on exit control event to change the system keyboard language 

    \e.g.
    ****************************************************

    Private Sub A_Enter()
    
    
    
     Me.A.KeyboardLanguage = 49
    
    
    
    End Sub
    
    
    
    Private Sub A_Exit(Cancel As Integer)
    
    
    
     Me.A.KeyboardLanguage = 11
    
    
    
     'this works(it means that keyboard language for ctl is changed back on english - 11, but system keyboard language remain on 49)
    
     'so i need here to change system keyboard language
    
     
    
    End Sub
    
    
    
    
    
    

    *************************************************

    • Edited by MBMSOFT Monday, May 17, 2010 4:24 PM
    Saturday, May 15, 2010 4:14 AM

Answers

  • Hello,

    In this case we could make use of Windows API to change the keyboard language globally, the Windows API we need is following:
    Private Declare Function GetKeyboardLayoutList Lib "user32.dll" (ByVal
    nBuff As Integer, ByVal lpList As Long) As Long
    Private Declare Function GetKeyboardLayout Lib "user32.dll" (ByVal
    dwLayout As Long) As Long
    Private Declare Function ActivateKeyboardLayout Lib
    "user32.dll" (ByVal HKL As Long, Flag As Boolean) As Long
    Private Declare Function LoadKeyboardLayout Lib "user32.dll" Alias
    "LoadKeyboardLayoutA" (ByVal pwszKLID As Long, Flag As Boolean) As
    Long
    Private Declare Function GetKeyboardLayoutName Lib "user32.dll" Alias
    "GetKeyboardLayoutNameA" (ByVal pwszKLID As Long) As Long

    I quote the code from this link:
    http://www.rhinocerus.net/forum/databases-ms-access/508487-setting-language-non-unicode-programs-programmatically.html

    Thanks.

     


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    • Marked as answer by MBMSOFT Monday, May 17, 2010 7:01 PM
    • Unmarked as answer by MBMSOFT Monday, May 17, 2010 7:01 PM
    • Marked as answer by Tim Li Tuesday, May 18, 2010 2:00 AM
    Monday, May 17, 2010 9:43 AM
  • Thanks Tim Li
    I follow your step...
    I did modify the way how to manage this issue and it works now , so if it is helpfull for someone here it is:
    Quote:

    Private Declare Function ActivateKeyboardLayout Lib _
    "user32.dll" (ByVal myLanguage As Long, Flag As Boolean) As Long

    'define your desired keyboardlanguage
    'find your desired language at http://www.trigeminal.com/frmrpt2dap.asp

    Private Const MKD = 1071 'macedonian keyboard language layout
    Private Const eng = 1033 'english(united states)keyboard language layout


    Private Sub A_Enter()

    'switch to your desired language
    Call ActivateKeyboardLayout(MKD, 0)

    End Sub

    Private Sub A_Exit(Cancel As Integer)

    'switch back to english(united states)
    Call ActivateKeyboardLayout(eng, 0)

    End Sub

    • Marked as answer by MBMSOFT Monday, May 17, 2010 7:06 PM
    Monday, May 17, 2010 7:05 PM

All replies

  • Hello,

    In this case we could make use of Windows API to change the keyboard language globally, the Windows API we need is following:
    Private Declare Function GetKeyboardLayoutList Lib "user32.dll" (ByVal
    nBuff As Integer, ByVal lpList As Long) As Long
    Private Declare Function GetKeyboardLayout Lib "user32.dll" (ByVal
    dwLayout As Long) As Long
    Private Declare Function ActivateKeyboardLayout Lib
    "user32.dll" (ByVal HKL As Long, Flag As Boolean) As Long
    Private Declare Function LoadKeyboardLayout Lib "user32.dll" Alias
    "LoadKeyboardLayoutA" (ByVal pwszKLID As Long, Flag As Boolean) As
    Long
    Private Declare Function GetKeyboardLayoutName Lib "user32.dll" Alias
    "GetKeyboardLayoutNameA" (ByVal pwszKLID As Long) As Long

    I quote the code from this link:
    http://www.rhinocerus.net/forum/databases-ms-access/508487-setting-language-non-unicode-programs-programmatically.html

    Thanks.

     


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    • Marked as answer by MBMSOFT Monday, May 17, 2010 7:01 PM
    • Unmarked as answer by MBMSOFT Monday, May 17, 2010 7:01 PM
    • Marked as answer by Tim Li Tuesday, May 18, 2010 2:00 AM
    Monday, May 17, 2010 9:43 AM
  • Thanks Tim Li
    I follow your step...
    I did modify the way how to manage this issue and it works now , so if it is helpfull for someone here it is:
    Quote:

    Private Declare Function ActivateKeyboardLayout Lib _
    "user32.dll" (ByVal myLanguage As Long, Flag As Boolean) As Long

    'define your desired keyboardlanguage
    'find your desired language at http://www.trigeminal.com/frmrpt2dap.asp

    Private Const MKD = 1071 'macedonian keyboard language layout
    Private Const eng = 1033 'english(united states)keyboard language layout


    Private Sub A_Enter()

    'switch to your desired language
    Call ActivateKeyboardLayout(MKD, 0)

    End Sub

    Private Sub A_Exit(Cancel As Integer)

    'switch back to english(united states)
    Call ActivateKeyboardLayout(eng, 0)

    End Sub

    • Marked as answer by MBMSOFT Monday, May 17, 2010 7:06 PM
    Monday, May 17, 2010 7:05 PM
  • Hi, Do you know about Khmer Keyboard number ?

    Best Regard 

    Sunleng

    Tuesday, September 20, 2016 4:14 AM