Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Set CAPS and NUM lock state in status bar

Status
Not open for further replies.

ozhiker

Programmer
Sep 10, 2002
3
AU
Hi,

I have the following code to check the current state of the caps lock and display it in my status bar - which event should I link it to so it will run whenever keys are pressed in the program (Currently I have it attached to OnFormCreate and OnPaint).

procedure TfrmEditor.CheckCapslock ();
begin
if Odd (GetKeyState (VK_CAPITAL)) then
sbStatusBar.Panels[sbpCaps].Text := 'CAPS'
else
sbStatusBar.Panels[sbpCaps].Text := '';
end;

thanks

ozhiker
 
the best spot to put it is most likely the forms onkeypress event, (this captures all key presses from your app) and set the forms keypreview property to true.
 
sure you can get vcl's to do all the work for you, but then how can you call yourself a programmer ??
 
Hi thanks for the help guys, I have added my code to the forms OnKeyPress event - this updates the Num/Caps nicely whenever a key is pressed, just not the numlock and caps keys!!! I believe this is because it is only looking for ANSI key press? Any ideas??

thanks

ozhiker
 
Use OnKeyDown event instead of OnKeyPress. HTH.

--- markus
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top