Mega Code Archive

 
Categories / Delphi / Hardware
 

Checking for Numlock and Capslock and displaying on Statusbar

Title: Checking for Numlock and Capslock and displaying on Statusbar Question: How do I check for a Numlock enabled and Capslock enable? Answer: Here are two procedures that you add to the main form of your application: Procedure TfrmMain.CheckCapslock; Begin if Odd(Getkeystate (VK_CAPITAL)) THEN Statusline.Panels[1].text:='CAPS' else Statusline.Panels[1].text:=''; end; Procedure TfrmMain.CheckNumlock; Begin if Odd(Getkeystate (VK_NUMLOCK)) THEN Statusline.Panels[2].text:='NUM' else Statusline.Panels[2].text:=''; end; Add a application component to your project and simply call both these procedures in the Application.onmessage event i.e.: procedure TfrmMain.ApplicationEvents1Message(var Msg: tagMSG; var Handled: Boolean); begin CheckCapslock; CheckNumlock; end; Hope someone finds this helpful... Kevin