Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Setting the keyboard state

Posted on 1997-12-12
3
Medium Priority
?
193 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

Independent Software Vendors: 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!

Question has a verified solution.

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

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…
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…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses

963 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