$hWnd = 0
;$hWnd = WinGetHandle('[REGEXPCLASS:Notepad.*]')
;SendKeepActive($hWnd)
_SendEx('!+^g', 0, $hWnd)
Func _SendEx($sKeys, $iFlag = 0, $hWnd = 0)
Local Const $WM_INPUTLANGCHANGEREQUEST = 0x50
Local Const $KEYEVENTF_KEYUP = 0x2
Local Const $VK_SHIFT = 0x10
Local Const $VK_CONTROL = 0x11
Local Const $VK_MENU = 0x12
If $hWnd = 0 Then
$hWnd = WinGetHandle('[ACTIVE]')
EndIf
Local $aLayout = DllCall("user32.dll", "long", "LoadKeyboardLayoutW", "wstr", Hex(0x0409, 8), "int", 0)
If Not @error And $aLayout[0] Then
Local $aOld_KL
Local $hAutoItWnd = WinGetHandle(AutoItWinGetTitle())
Local $aProcID = DllCall('user32.dll', 'dword', 'GetWindowThreadProcessId', 'hwnd', $hWnd, 'ptr', 0)
If Not @error And $aProcID[0] Then
$aOld_KL = DllCall('user32.dll', 'handle', 'GetKeyboardLayout', 'dword', $aProcID[0])
EndIf
;Set keyboard layout for target and internal autoit window
DllCall("user32.dll", "ptr", "SendMessage", "hwnd", $hWnd, "int", $WM_INPUTLANGCHANGEREQUEST, "int", 1, "int", $aLayout[0])
DllCall("user32.dll", "ptr", "SendMessage", "hwnd", $hAutoItWnd, "int", $WM_INPUTLANGCHANGEREQUEST, "int", 1, "int", $aLayout[0])
Send($sKeys, $iFlag)
;Release modifier keys
DllCall('user32.dll', 'none', 'keybd_event', 'byte', $VK_SHIFT, 'byte', 0, 'dword', $KEYEVENTF_KEYUP, 'ulong_ptr', 0)
DllCall('user32.dll', 'none', 'keybd_event', 'byte', $VK_CONTROL, 'byte', 0, 'dword', $KEYEVENTF_KEYUP, 'ulong_ptr', 0)
DllCall('user32.dll', 'none', 'keybd_event', 'byte', $VK_MENU, 'byte', 0, 'dword', $KEYEVENTF_KEYUP, 'ulong_ptr', 0)
;Restore keyboard layout
If IsArray($aOld_KL) Then
DllCall("user32.dll", "ptr", "SendMessage", "hwnd", $hWnd, "int", $WM_INPUTLANGCHANGEREQUEST, "int", 1, "int", $aOld_KL[0])
EndIf
Return SetError(0)
EndIf
Return SetError(1)
EndFunc