Solved

Toggle Caps lock

Posted on 1997-05-26
1
463 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 20 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

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

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

Suggested Solutions

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

828 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