954,568 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?

KeyPress Versus KeyUp and KeyDown

0
By Jhai Salvador on Dec 27th, 2010 9:15 pm

Okay, this is just a simple trick to determine whether CAPS is pressed because some people here use API to determine whether the CAPS Lock is pressed.

KeyDown and KeyUp don't detect exactly the same information as KeyPress.

KeyPress detects a character in its KeyAscii parameter, but KeyDown and KeyUp detect a physical keystroke in their KeyCode parameter.

  • KeyUp and KeyDown can detect keystrokes not recognized by KeyPress, such as function, editing, and navigation keys.
  • KeyPress can distinguish between different ASCII characters generated by the same physical keystroke.

Where did I get KeyCode = 20? Try to use a breakpoint on Text1_KeyDown event to get the keycode of the Caps Lock. This will just be available on KeyDown event.

Hopes this helps.

Private Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = 20 Then
   MsgBox "CAPS is Pressed"
End If
End Sub

I have asked the mods to move this to Snippets.:)

AndreRet
Senior Poster
3,922 posts since Jan 2008
Reputation Points: 334
Solved Threads: 350
 

Thank you.

jhai_salvador
Junior Poster
180 posts since Mar 2008
Reputation Points: 33
Solved Threads: 34
 

Done. Next time, when creating a new thread, please select "code snippet" from the combobox. (it reads "discussion thread" standard).

Nick Evan
Not a Llama
Moderator
10,112 posts since Oct 2006
Reputation Points: 4,142
Solved Threads: 403
 

Thanks, I just forget to set it to the correct discusion section because I am at the Code Snippet tab when I created this thread, so I hope mods will also fix the default combo box value when creating threads. Thanks.

jhai_salvador
Junior Poster
180 posts since Mar 2008
Reputation Points: 33
Solved Threads: 34
 

The only person who can do that is the queen herself. We humble minions do not have that power :)

Nick Evan
Not a Llama
Moderator
10,112 posts since Oct 2006
Reputation Points: 4,142
Solved Threads: 403
 

Oh yeah, the queen herself.;)

AndreRet
Senior Poster
3,922 posts since Jan 2008
Reputation Points: 334
Solved Threads: 350
 

oh.. I didn't know that..

jhai_salvador
Junior Poster
180 posts since Mar 2008
Reputation Points: 33
Solved Threads: 34
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: