Const RusChars As String = "йцукенгшщзхъфывапролджэячсмитьбю"
Const EngChars As String = "qwertyuiop[]asdfghjkl;'zxcvbnm,."
Function TranslateLetter (L As String, Optional ToEnglish As Boolean = True) As String
TranslateLetter = Mid$(IIF(ToEnglish, EngChars, RusChars), InStr(IIF(ToEnglish, RusChars, EngChars), L))
End Function
'This example was created by A.E.Veltstra
'This fucntion changes the locale and as a result, the keyboardlayout gets adjusted
'parameters for api's
Const KL_NAMELENGTH As Long = 9 'length of the keyboardbuffer
Const KLF_ACTIVATE As Long = &H1 'activate the layout
'the language constants
Const LANG_EN_US As String = "00000409"
Const LANG_RUS As String = "00000419"
'api's to adjust the keyboardlayout
Private Declare Function GetKeyboardLayoutName Lib "user32" Alias "GetKeyboardLayoutNameA" (ByVal pwszKLID As String) As Long
Private Declare Function LoadKeyboardLayout Lib "user32" Alias "LoadKeyboardLayoutA" (ByVal pwszKLID As String, ByVal flags As Long) As Long
Public Function SetKbLayout(strLocaleId As String) As Boolean
'Changes the KeyboardLayout
'Returns TRUE when the KeyboardLayout was adjusted properly, FALSE otherwise
'If the KeyboardLayout isn't installed, this function will install it for you
On Error Resume Next
Dim strLocId As String 'used to retrieve current KeyboardLayout
Dim strMsg As String 'used as buffer
Dim lngErrNr As Long 'receives the API-error number
'create a buffer
strLocId = String(KL_NAMELENGTH, 0)
'retrieve the current KeyboardLayout
GetKeyboardLayoutName strLocId
MsgBox strLocId
'Check whether the current KeyboardLayout and the
'new one are the same
If strLocId = (strLocaleId & Chr(0)) Then
'If they're the same, we return immediately
SetKbLayout = True
Else
'create buffer
strLocId = String(KL_NAMELENGTH, 0)
'load and activate the layout for the current thread
strLocId = LoadKeyboardLayout((strLocaleId & Chr(0)), KLF_ACTIVATE)
If IsNull(strLocId) Then 'returns NULL when it fails
SetKbLayout = False
Else 'check again
'create buffer
strLocId = String(KL_NAMELENGTH, 0)
'retrieve the current layout
GetKeyboardLayoutName strLocId
If strLocId = (strLocaleId & Chr(0)) Then
SetKbLayout = True
Else
SetKbLayout = False
End If
End If
End If
End Function
Возможно ли как нибудь изменить язык для любого процесса, зная его ID или hwnd окна?GSerg писал(а):Хозяин-барин
Добавь это в форму. А чтобы изменять раскладку, вызывай функцию:
SetKbLayout LANG_EN_US или SetKbLayout LANG_RUS
Сейчас этот форум просматривают: Google-бот и гости: 92