Solved

How to change the keyboard state??

Posted on 1997-12-13
7
170 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

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…
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…

911 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

19 Experts available now in Live!

Get 1:1 Help Now