Mega Code Archive

 
Categories / Delphi / Hardware
 

How to turn CAPS LOCK on or off

Title: How to turn CAPS LOCK on or off Question: How to set the Caps-Lock key... ? Answer: Here is the function: procedure SetCapsLockKey( vcode: Integer; down: Boolean ); begin if Odd(GetAsyncKeyState( vcode )) down then begin keybd_event( vcode, MapVirtualkey( vcode, 0 ), KEYEVENTF_EXTENDEDKEY, 0); keybd_event( vcode, MapVirtualkey( vcode, 0 ), KEYEVENTF_EXTENDEDKEY or KEYEVENTF_KEYUP, 0); end; end; ... SetLockKey( VK_CAPITAL, True ); // 'press' it 'keybd_event', 'MapVirtualkey' and 'GetAsyncKeyState' are win-api function...