Solved

How to change the keyboard state??

Posted on 1997-12-13
7
169 Views
Last Modified: 2010-04-04
I need the code to change the NumLock Key state by clicking on a button of my application

Have tried using the following code but it does not seem to work
keybd_event(VK_NUMLOCK, 0, 0, 0);
keybd_event(VK_NUMLOCK, 0, KEYEVENTF_KEYUP, 0);

The above code works when substituted with VK_CAPITAL or VK_INSERT but not VK_NUMLOCK. Anyone knows why?

By the way, I took the code from another person's answer
(Ermac I think...) and he had the same problem as me








0
Comment
Question by:WizKid
  • 3
  • 2
  • 2
7 Comments
 
LVL 1

Expert Comment

by:miv
ID: 1353518
Turn this around :-)

------------------------------------

FUNCTION GetKeybStatus : TKeybStatusSet;
VAR
  KeybAbs: Byte absolute $0040:$0097;

  BEGIN
    Result:= [];
    IF (KeybAbs and 4)=4 THEN
      Result:= [ksCapsLock];
    IF (KeybAbs and 2)=2 THEN
      Result:= Result+[ksNumLock];
    IF (KeybAbs and 1)=1 THEN
      Result:= Result+[ksScrollLock];
  END;


0
 

Author Comment

by:WizKid
ID: 1353519
I think you got me wrong....
The code that you gave me is only used for detecting the status of the keyboard but what I wanted was to set the them (Eg. Toggle the Num Lock key)


0
 
LVL 1

Expert Comment

by:miv
ID: 1353520
Yes, just set the 0040:0097 adress instead of reading it...?
0
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 

Author Comment

by:WizKid
ID: 1353521
Tried your code already but it doesn't work on Delphi 3.0 (32 bit). It just can't compile...

Any other way?
0
 
LVL 8

Accepted Solution

by:
ZifNab earned 50 total points
ID: 1353522

try this... (from UDDF)

procedure TMyForm.Button1Click(Sender: TObject);
  Var
    KeyState  :  TKeyboardState;
  begin
    GetKeyboardState(KeyState);
    if (KeyState[VK_NUMLOCK] = 0) then
      KeyState[VK_NUMLOCK] := 1
    else
      KeyState[VK_NUMLOCK] := 0;
    SetKeyboardState(KeyState);
  end;

for caps lock substitute VK_CAPITAL for VK_NUMLOCK.
0
 

Author Comment

by:WizKid
ID: 1353523
It worked! Thanks Pal!
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1353524
No problem, glad I could help.

Good luck with it!
c.u. Zif.
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

706 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now