在Windows上使用Delphi更改键盘布局
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了在Windows上使用Delphi更改键盘布局相关的知识,希望对你有一定的参考价值。
我想用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中每个进程的键盘布局?我是否需要在注册表中进行一些更改?
答案
根据您的评论,您想要的是阻止RDP连接更改您的本地键盘布局。
另一答案
//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}
以上是关于在Windows上使用Delphi更改键盘布局的主要内容,如果未能解决你的问题,请参考以下文章