Solved

Setting the keyboard state

Posted on 1997-12-12
3
175 Views
Last Modified: 2010-04-04
I need to enable the Num Lock, Caps Lock and Insert/Overwrite Key by just clicking on a button

I have tried using the SetKeyBoardState function but found that it does not do this
Is there any way to do this??

Please Help....
Thanks in Advance
0
Comment
Question by:ermac
  • 2
3 Comments
 
LVL 1

Accepted Solution

by:
zac earned 70 total points
ID: 1353445
SetKeyBoardState only changes the state of the keyboard for the thread from which it was called, consequently you cannot change the global keyboard state using this function.

There is a fudge however, simply send the keystrokes themselves to windows the code I use is below:

  keybd_event(VK_NUMLOCK, 0, 0, 0);
  keybd_event(VK_NUMLOCK, 0, KEYEVENTF_KEYUP, 0);

You need both calls, one for the press event and one for the key up event.  This code will toggle the NUMLOCK status of the keyboard.

If you need to set a particular state, then I suggest you look at the keyboard state using GetKeyState and then make the changes where necessary.


I hope this helps.


PS Virtual key codes you will need:

NUMLOCK  -  VK_NUMLOCK
CAPSLOCK -  VK_CAPITAL
Insert           -  VK_INSERT

However I believe the insert/ovewrite toggle is implemented in each application and therefore you might have to give the application input focus before sending the commands.
0
 

Author Comment

by:ermac
ID: 1353446
Great! It works except for the Num Lock key...

I've even tried it using a brand new project
Both the Caps Lock and the Insert/Overwrite Key works perfectly but not the Num Lock key
Why??

Increased Points to 75


0
 
LVL 1

Expert Comment

by:zac
ID: 1353447
They code fragment I supplied was code that I tested ie with the NUMLOCK key - it worked!  However I use windows NT for all my development.
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
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…
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…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

809 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