如何通过 ctypes python 设置用户的输入语言?

How to set the user's typing language via ctypes python?

win32api & pyhook - How to get the user's typing language?

在这个主题中有明确的答案如何获取当前用户语言,但我想使用 set 和 get。

这可能应该是一个函数

ctypes.windll.user32.ActivateKeyboardLayout()

有一些参数。

有没有办法python如何使用这个函数(就像上面主题中描述的那样?)

我刚刚阅读了问题更新(已还原)。以下是如何通过 [Python 3.Docs]: ctypes - A foreign function library for Python:

code00.py:

#!/usr/bin/env python3

import sys
import ctypes
from ctypes import wintypes


KLF_ACTIVATE = 0x00000001


def main():
    locale_id_bytes = b"00000409"
    klid = ctypes.create_string_buffer(locale_id_bytes)
    user32_dll = ctypes.WinDLL("user32")
    kernel32_dll = ctypes.WinDLL("kernel32")
    LoadKeyboardLayout = user32_dll.LoadKeyboardLayoutA
    LoadKeyboardLayout.argtypes = [wintypes.LPCSTR, wintypes.UINT]
    LoadKeyboardLayout.restype = wintypes.HKL
    GetLastError = kernel32_dll.GetLastError
    GetLastError.restype = wintypes.DWORD

    klh = LoadKeyboardLayout(klid, KLF_ACTIVATE)
    print("{0:s} returned: 0x{1:016X}".format(LoadKeyboardLayout.__name__, klh))
    print("{0:s} returned: {1:d}".format(GetLastError.__name__, GetLastError()))


if  __name__ == "__main__":
    print("Python {0:s} {1:d}bit on {2:s}\n".format(" ".join(item.strip() for item in sys.version.split("\n")), 64 if sys.maxsize > 0x100000000 else 32, sys.platform))
    main()
    print("\nDone.")

输出:

[cfati@CFATI-5510-0:e:\Work\Dev\Whosebug\q048287040]> "e:\Work\Dev\VEnvs\py_064_03.07.03_test0\Scripts\python.exe" code00.py
Python 3.7.3 (v3.7.3:ef4ec6ed12, Mar 25 2019, 22:22:05) [MSC v.1916 64 bit (AMD64)] 64bit on win32

LoadKeyboardLayoutA returned: 0x0000000004090409
GetLastError returned: 0

Done.

有关 [MS.Docs]: LoadKeyboardLayoutA function 的更多(与主题相关的)详细信息。