Solved

How to change the keyboard state??

Posted on 1997-12-13
7
173 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

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

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
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…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

738 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