Solved

Setting the keyboard state

Posted on 1997-12-12
3
187 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
[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
  • 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

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
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…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Suggested Courses
Course of the Month4 days, 13 hours left to enroll

636 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