Solved

Setting the keyboard state

Posted on 1997-12-12
3
171 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

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
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…

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

15 Experts available now in Live!

Get 1:1 Help Now