I'm trying to write code to switch the keyboard layout with the Caps-Lock key. I find it most convenient to switch the layout with the little finger of my left hand instead of cumbersome combinations with Ctrl and Alt, which knock down the rhythm of the set (and now it is so). Something working out turned out, but the problem is that the Caps-Lock button is processed by the system and although the code switches it back, these milliseconds during speed dialing greatly hinder and slow down typing. In addition, I am not a programmer so do not judge strictly, I do not understand how to make the code global. Here is the code itself:
procedure TForm1.Timer1Timer(Sender: TObject); var Layout: array[0.. KL_NAMELENGTH] of char; begin if GetAsyncKeyState(VK_CAPITAL)<>0 then begin GetKeyboardLayoutName(Layout); if Layout = '00000419' then LoadKeyboardLayout('00000409', 1) else if Layout = '00000409' then LoadKeyboardLayout('00000419', 1); Keybd_Event(VK_CAPITAL, 0, KEYEVENTF_EXTENDEDKEY or 0, 0); //Keybd_Event(VK_CAPITAL, 0, KEYEVENTF_EXTENDEDKEY or KEYEVENTF_KEYUP, 0); //keybd_event(VK_CAPITAL, 1, 0, 0); keybd_event(VK_CAPITAL, 1, vk_up, 0); timer1.Enabled:=false; end; end; procedure TForm1.Timer2Timer(Sender: TObject); begin if GetAsyncKeyState(VK_CAPITAL) = 0 then timer1.Enabled:=true; end;