如何在Windows(c++)中更改语言键盘布局

How can change language keyboard layout in Windows (c++)

本文关键字:语言 键盘 布局 Windows c++      更新时间:2023-10-16

我需要更改键盘语言。有了这段代码,如果在焦点应用程序中,我可以更改语言:

#include <cstdlib>
#include <iostream>
#include <windows.h>
#include <stdio.h>
#include <string>
using namespace std;
#pragma comment(lib, "User32.lib")

int main(int argc, char *argv[])
{
   //0409 - Ingles, 0c0a - Espanhol, 0416 - Portugues
   char *str = "0c0a";//argv[1];
   int i;
    if(EOF != sscanf(str, "%x", &i))
   {
      SendMessage(GetActiveWindow(), WM_INPUTLANGCHANGEREQUEST, 0, i);
   }
   system("PAUSE");
   return EXIT_SUCCESS;
}

但我肯定需要更改系统键盘语言,在应用程序关闭或如果未在应用程序中设置焦点。

有人能帮我吗?

如果确实需要更改用户的键盘布局,可以使用以下功能:GetKeyboardLayoutName()和LoadKeyboardLayer()。