I want to change the keyboard layout in Windows with Delphi. I successfully could do this with following code but it seems it only changes for one process/thread and not for every process.
// 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.
Does anyone know how I could change the keyboard layout for every process in Windows? Do I need to make some changes in Registry?