Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Toggle Caps lock

Posted on 1997-05-26
1
Medium Priority
?
474 Views
Last Modified: 2010-04-04
How do I toggle Caps lock on/off
0
Comment
Question by:Jens204
1 Comment
 
LVL 4

Accepted Solution

by:
erajoj earned 40 total points
ID: 1336594
This code will toggle the CapsLock state in NT/Win95:

procedure TMainForm.Button10Click(Sender: TObject);
Var
  KeyState  :  TKeyboardState;
begin
  GetKeyboardState(KeyState); {Only to check current state}
  keybd_event( VK_CAPITAL, $45, KEYEVENTF_EXTENDEDKEY, 0 );
  keybd_event( VK_CAPITAL, $45, KEYEVENTF_EXTENDEDKEY or KEYEVENTF_KEYUP, 0);
end;

To find out if CapsLock is on then check KeyState[VK_CAPITAL].
(0=off/1=on)
--------------------------------------------------------------
This code will toggle the CapsLock state in Windows 3.x:

procedure TMainForm.Button10Click(Sender: TObject);
Var
  KeyState  :  TKeyboardState;
begin
  GetKeyboardState(KeyState);
  KeyState[VK_CAPITAL] := KeyState[VK_CAPITAL] xor 1;
  SetKeyboardState(KeyState);
end;

This will also work with VK_NUMLOCK.

Enjoy!

/// John

0

Featured Post

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses

782 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question