473,386 Members | 1,823 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Detect whether Caps Lock key pressed?

yxq
Hello,
I have a main form, there other some controls(i.e. textbox) in the form.
I want to detect whether Caps Lock key is pressed in form-key event.

Private Sub Form1_KeyUp(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyUp
If e.KeyCode = 20 Then
MessageBox.Show("Caps Lock is pressed!")
End If
End Sub

But the code will not work, how to do? I guess the other controls accepted
the key?

Thank you
Nov 21 '05 #1
1 5655
Hi,

Use the getkeystate api. It will return true if the key is
active.
Declare Function GetKeyState Lib "user32" (ByVal nVirtKey As Integer) As
boolean

Const VK_NUMLOCK = 144

Const VK_CAPLOCK = 20

Ken

------------------
"yxq" <ga***@163.net> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
Hello,
I have a main form, there other some controls(i.e. textbox) in the form.
I want to detect whether Caps Lock key is pressed in form-key event.

Private Sub Form1_KeyUp(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyUp
If e.KeyCode = 20 Then
MessageBox.Show("Caps Lock is pressed!")
End If
End Sub

But the code will not work, how to do? I guess the other controls accepted
the key?

Thank you

Nov 21 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Rune | last post by:
Hey I'm trying to build a gui application and need to know if the user is actually holding down the shift or ctrl key. That is, if the user currently is holding down the shift key. In pseudo...
18
by: Robert | last post by:
Hi! I was wondering if the was any way to determine the state of the caps lock key, on or off. Of course I can capture the key events and see whether the caps lock is pressed, but that does not...
3
by: Tegdeep | last post by:
Here's what I want to do: I have a hash table which contains data associated to different keys. The Hash keys are represented by a single character from the keyboard: 0-9, a-z, A-Z, and the...
0
by: fNew VBer | last post by:
Hi. I'm new to Visual Basic .NET, so you'll have to bear with me . . . I want to create an app that turns off CAPS LOCK when the SHIFT key is pressed. I got the code to turn off CAPS LOCK to...
1
by: charlies224 | last post by:
Hi, I am writting a software that requires me to make sure the Num Lock is always on and Caps Lock is always off. First, I know how to detect if Num Lock or Caps Lock is on or off (if...
1
by: Brian Parker | last post by:
I play a DirectX game and while that game is running, I would like to change the behavior of the Caps Lock key. When it's pressed, I don't want it to toggle my Caps Lock on and off, but instead...
2
by: Justin | last post by:
I'm creating a kiosk type application and this would be too simple for someone to figure out: Private Declare Function GetAsyncKeyState Lib "user32" ( ByVal vKey As Short) As Short Const...
6
by: marss | last post by:
Hi, How can I define in Firefox whether the left mouse button is pressed when I move mouse over a html element? The documentation says that "e.button == 0 for standard 'click', usually left...
4
by: zacks | last post by:
I'm not sure when it came into being, since this it the first time I have worked very much with a password control in .NET, but if a textbox that has a non-empty value for PasswordChar or the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.