在Windows上使用Delphi更改键盘布局

时间:2015-02-20 08:20:48

标签: windows delphi keyboard-layout

我想用Delphi更改Windows中的键盘布局。我成功地可以使用以下代码执行此操作,但它似乎只会更改 one process/thread ,而不是针对每个流程。

// Array with 4 keyboard layout codes (in decimal)
const KLS: array [0 .. 3] of integer = (2055, 4108, 2064, 2057);
KLF_SETFORPROCESS = $00000100;

// The TForm1 contains a RadioGroup1 with 4 Radiobuttons 
procedure TForm1.btn_activateLayoutClick(Sender: TObject);

begin
  SetKeyboardLayout(RadioGroup1.ItemIndex);
end;

// set the new keyboard layout according to the ItemIndex of the RadioGroup1
procedure TForm1.SetKeyboardLayout(const klsIndex: integer);
var
  klId: array [0 .. 9] of char;
  keyboardCode: integer;
begin
  keyboardCode := KLS[klsIndex];

  try
     ActivateKeyboardLayout(keyboardCode, KLF_SETFORPROCESS or KLF_ACTIVATE, KLF_SETFORPROCESS)
  finally
     raise Exception.Create('Error while changing keyboard layout');
  end;
end;
end.

有谁知道如何在Windows中更改每个进程的键盘布局 ?我是否需要在注册表中进行一些更改?

2 个答案:

答案 0 :(得分:0)

根据您的评论,您想要的是阻止RDP连接更改您的本地键盘布局。

可以在此处找到答案: https://superuser.com/questions/426356/how-can-i-stop-the-remote-computer-from-changing-my-keyboard-layout

答案 1 :(得分:-1)

//Winapi.windows
LoadKeyBoardLayout('0000040A',1); //Spanish keyboard
LoadKeyBoardLayout('00000409',1); //English (US) keyboard
//https://docs.microsoft.com/en-us/windows/iot-core/develop-your-
app/onscreenkeyboardlayouts  windows page for keyboards
{The keyboard has to be loaded already under "Region & Language" -->
English (United States) --> Options --> +Add a keyboard --> US QWERTY
and Spanish QWERTY}