I am trying to change the keyboard language in python (windows). I have searched everywhere for a way to do it and the most common answer is
import win32api
win32api.LoadKeyboardLayout('00000409',1) # to switch to english
win32api.LoadKeyboardLayout('00000401',1) # to switch to arabic
But the only thing this code does is add another language to the current list of languages on my pc - it doesn't change the language's keyboard (when I try typing something after I ran the script it keeps typing in the same language). BTW, I am using windows
Thank you in advance for any help!
This is works for me
from win32con import WM_INPUTLANGCHANGEREQUEST
from win32gui import GetForegroundWindow
from win32api import SendMessage
if SendMessage( GetForegroundWindow(), WM_INPUTLANGCHANGEREQUEST, 0, 0x4090409) == 0:
print('設定英文鍵盤成功!')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With