Friday, December 30, 2011

Get GetKeyboardLayout language from a thread

Option Explicit  
'Get GetKeyboardLayout language from a thread
'Original code by Gringo Man
Private Declare Function GetKeyboardLayout Lib "user32" (ByVal dwLayout As Long) As Long
Private Declare Function
GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, lpdwProcessId As Long) As Long

Public Sub
KeyBoardLanguage()

Dim
TheardId As Long
Dim
TheardLang As Long
Dim
processid As Long

TheardId = GetWindowThreadProcessId(hwnd, processid)
TheardLang = GetKeyboardLayout(ByVal TheardId)
TheardLang = TheardLang Mod 10000

If
TheardLang = "9721" Then
MsgBox "English"
ElseIf
TheardLang = "5425" Then
MsgBox "Arabic"
End If

End Sub

Private Sub
Command1_Click()
KeyBoardLanguage
End Sub
READ MORE - Get GetKeyboardLayout language from a thread