• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 417
  • Last Modified:

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?
0
petershaw8
Asked:
petershaw8
1 Solution
 
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
 
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
[Webinar] Improve your customer journey

A positive customer journey is important in attracting and retaining business. To improve this experience, you can use Google Maps APIs to increase checkout conversions, boost user engagement, and optimize order fulfillment. Learn how in this webinar presented by Dito.

 
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

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now