LostProph Posted July 24, 2009 Share Posted July 24, 2009 Hi! I'm trying to create a script that when a hotkey is pressed it will change your keyboard layout. Originally i thought i could do it through regedit, but this attempt has failed. If RegRead("HKCU\Keyboard Layout\Preload", "1") <> "00000409" Then RegWrite("HKCU\Keyboard Layout\Preload", "1", "REG_SZ", "00000409") EndIf Anyone can help me on this matter? Link to comment Share on other sites More sharing options...
LostProph Posted July 24, 2009 Author Share Posted July 24, 2009 have found below code: Func _WinAPI_GetKeyboardLayout($hWnd) Local $Ret = DllCall('user32.dll', 'long', 'GetWindowThreadProcessId', 'hwnd', $hWnd, 'ptr', 0) If (@error) Or ($Ret[0] = 0) Then Return SetError(1, 0, 0) EndIf $Ret = DllCall('user32.dll', 'long', 'GetKeyboardLayout', 'long', $Ret[0]) If (@error) Or ($Ret[0] = 0) Then Return SetError(1, 0, 0) EndIf Return '0000' & Hex($Ret[0], 4) EndFunc ;==>_WinAPI_GetKeyboardLayout Func _WinAPI_SetKeyboardLayout($sLayout, $hWnd) If Not WinExists($hWnd) Then Return SetError(1, 0, 0) EndIf Local $Ret = DllCall('user32.dll', 'long', 'LoadKeyboardLayout', 'str', StringFormat('%08s', StringStripWS($sLayout, 8)), 'int', 0) If (@error) Or ($Ret[0] = 0) Then[url="http://msdn.microsoft.com/en-us/library/dd318693(VS.85).aspx"]http://msdn.microsoft.com/en-us/library/dd318693(VS.85).aspx[/url] Return SetError(1, 0, 0) EndIf DllCall('user32.dll', 'ptr', 'SendMessage', 'hwnd', $hWnd, 'int', 0x0050, 'int', 1, 'int', $Ret[0]) Return SetError(0, 0, 1) EndFunc ;==>_WinAPI_SetKeyboardLayout to read and change keyboard layout... but as im still a bit new to autoit, i don't fully understand the above code Why is the variable '$hWnd' for? Link to comment Share on other sites More sharing options...
99ojo Posted July 24, 2009 Share Posted July 24, 2009 have found below code: Func _WinAPI_GetKeyboardLayout($hWnd) Local $Ret = DllCall('user32.dll', 'long', 'GetWindowThreadProcessId', 'hwnd', $hWnd, 'ptr', 0) If (@error) Or ($Ret[0] = 0) Then Return SetError(1, 0, 0) EndIf $Ret = DllCall('user32.dll', 'long', 'GetKeyboardLayout', 'long', $Ret[0]) If (@error) Or ($Ret[0] = 0) Then Return SetError(1, 0, 0) EndIf Return '0000' & Hex($Ret[0], 4) EndFunc ;==>_WinAPI_GetKeyboardLayout Func _WinAPI_SetKeyboardLayout($sLayout, $hWnd) If Not WinExists($hWnd) Then Return SetError(1, 0, 0) EndIf Local $Ret = DllCall('user32.dll', 'long', 'LoadKeyboardLayout', 'str', StringFormat('%08s', StringStripWS($sLayout, 8)), 'int', 0) If (@error) Or ($Ret[0] = 0) Then[url="http://msdn.microsoft.com/en-us/library/dd318693(VS.85).aspx"]http://msdn.microsoft.com/en-us/library/dd318693(VS.85).aspx[/url] Return SetError(1, 0, 0) EndIf DllCall('user32.dll', 'ptr', 'SendMessage', 'hwnd', $hWnd, 'int', 0x0050, 'int', 1, 'int', $Ret[0]) Return SetError(0, 0, 1) EndFunc ;==>_WinAPI_SetKeyboardLayout to read and change keyboard layout... but as im still a bit new to autoit, i don't fully understand the above code Why is the variable '$hWnd' for? Hi, if you have only 2 layouts, e.g DE and EN then this should work as well: Send ("{ALTDOWN}{LSHIFT}") Send ("{ALTUP}") Link to comment Share on other sites More sharing options...
LostProph Posted August 11, 2009 Author Share Posted August 11, 2009 Hi, if you have only 2 layouts, e.g DE and EN then this should work as well: Send ("{ALTDOWN}{LSHIFT}") Send ("{ALTUP}") Hiya I have to switch between 3layouts, dutch period / french / en-us So i was actually looking to assign a hotkey to each layout. But i still find it hard to decypher the code i found myselfm as i have no reference to the variables used in the code and since im pretty new to using autoit Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now