you can Programmatically Get and Set the State of the CapsLock Keys using Keybd_Event function
try this:
var
KeyState: TKeyboardState;
begin
GetKeyboardState(KeyState) ;
if (KeyState[VK_CAPITAL] = 0) then
begin //simulate key down
Keybd_Event(VK_CAPITAL, 1, KEYEVENTF_EXTENDEDKEY or 0, 0) ;
Keybd_Event(VK_CAPITAL, 1, KEYEVENTF_EXTENDEDKEY or KEYEVENTF_KEYUP, 0) ;
end
else
begin //simulate key up
Keybd_Event(VK_CAPITAL, 0, KEYEVENTF_EXTENDEDKEY or 0, 0) ;
Keybd_Event(VK_CAPITAL, 0, KEYEVENTF_EXTENDEDKEY or KEYEVENTF_KEYUP, 0) ;
end;
if you REALLY want to disable a key(which i dont recommend) you can use this library called BlockKeys(i found BlockKeys library at http://www.experts-exchange.com/Programming/Languages/Pascal/Delphi/Q_21504230.html ):
library BlockKeys;
uses
Windows,
Messages;
{$R *.RES}
var
hKeyHook: THandle = 0;
Hooked: Boolean = False;
function HookFunc(Code, VirtualKey, KeyStroke: Integer): Integer; stdcall;
begin
if VirtualKey in [VK_TAB, VK_CONTROL, VK_MENU, VK_ESCAPE, VK_F1] then
Result := 32
else
Result := CallNextHookEx(hKeyHook, Code, VirtualKey, KeyStroke);
end;
function StartHook: Boolean; export;
begin
Result := False;
if Hooked then
begin
Result := True;
Exit;
end;
hKeyHook := SetWindowsHookEx(WH_KEYBOARD, HookFunc, hInstance, 0);
if hKeyHook <> 0 then
begin
Result := True;
Hooked := True;
end;
end;
function StopHook: Boolean; export;
begin
if Hooked then
Result := UnhookWindowsHookEx(hKeyHook)
else
Result := True;
if Result then Hooked := False;
end;
exports
StartHook,
StopHook;
begin
end.
hope this helps