Caps Lock key and Num Lock key

If I press Caps Lock key or Num Lock key
I wish the status bar shows 'Cap' or 'Num'. How can I do this?
petershaw8Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

mhervaisCommented:
the onkeydown event (parameter key) sould tell you when it happens.

you just have after to write what you need in the status bar

regards, Marc
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
BlackDeathCommented:
an example for retrieving CAPS state:

if (GetKeyState(VK_CAPITAL) and $01) <> 0 then
  // caps active
else
  // caps inactive

u can poll this in a timer event or put it in the keydown event of the form or in a message handling proc.

more?
0
BlackDeathCommented:
btw: i could send ya a statusbar component doing just this. post ur email addr; i'll send it ovuh 2 ya.

BlackDeath.
0
Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

philipleighsCommented:
You really have to poll because caps lock could be changed when another app has the focus. Your app would not get a keydown event.

BTW, here is how you can set and set the NUMLOCK state. (This is Microsoft's method. It is a translation of C code from the MSDN).

function GetNumLock: Boolean;
  var KeyState: Integer;
  begin
    KeyState := GetKeyState(VK_NUMLOCK);
    Result := KeyState and 1 = 1;
  end;

procedure SetNumLock(bState: Boolean);
  var KeyState: TKeyBoardState;
  begin
    GetKeyboardState(KeyState);
    if (bState and (KeyState[VK_NUMLOCK] and 1 = 0)) or
       ((not bState) and (KeyState[VK_NUMLOCK] and 1 = 1)) then
      begin
        // Simulate a key press
          keybd_event( VK_NUMLOCK,
                       $45,
                       KEYEVENTF_EXTENDEDKEY or 0,
                       0 );

        // Simulate a key release
          keybd_event( VK_NUMLOCK,
                       $45,
                       KEYEVENTF_EXTENDEDKEY or KEYEVENTF_KEYUP,
                       0);
      end;
  end;

Cheers,
Phil.
0
petershaw8Author Commented:
Thanks all of you.
My email address is exex8@hotmail.com.
It is very nice if Blackdeath send me your status bar. BTW, Blackdeath: what message handling proc should be?
0
BlackDeathCommented:
u can hook a message handling procedure in2 the message chain 4 keyboard events. there u'll get 2 parameters containing all u need bout the pressed key. i've got a sample @home. mayb i remember 2 bring it w/ me 2morrow so i can send it ovuh. it's 2 much trouble here @work 2 gather all i've needed the last time i wrote it. it's not so much the proc itself; it's the parameter evaluation.

the statusbar is on the way...

;-)

BlackDeath.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.