?
Solved

problem with keypress VS keydown

Posted on 2004-09-29
6
Medium Priority
?
1,239 Views
Last Modified: 2008-02-01
I put some coding both in the keypress event and keydown event. but the keypress event is not fired why? is it keydown suppress keypress?
0
Comment
Question by:jessi_vs
[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
6 Comments
 
LVL 33

Expert Comment

by:hongjun
ID: 12177486
post your code.
0
 
LVL 10

Expert Comment

by:ADSaunders
ID: 12177538
Hi jessi_vs,
Is the keypress event in the form or in a control on the form? If it is on the form, the keypress will only be seen if the KeyPreview property of the form is set to true.

Regards .. Alan
0
 
LVL 8

Expert Comment

by:mladenovicz
ID: 12177755
keypress event occurs when the user presses and releases an ANSI key.The object with the focus receives the event.
keydown event occurs when the user presses a key while an object has the focus.

0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 12

Expert Comment

by:jkaios
ID: 12187451
Yes, if both the KeyDown and KeyPress events are present, then the "KeyDown" event would fire, thus suppressing the KeyPress event.
0
 

Author Comment

by:jessi_vs
ID: 12187473
thanks, let me check it up. both events or in a textbox.
0
 
LVL 12

Accepted Solution

by:
jkaios earned 80 total points
ID: 12187772
Perhaps you might want to try this to confirm.

1. Place a text box on the form and call it Text1
2. Paste the following codes below
3. Run your app the hit some key -- you should confirm that only the KeyDown event fires

-----------------[Start of Code] ----------------------------------------------------------------

Private Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer)
 MsgBox "KeyCode = " & KeyCode, , "Text1_KeyDown"
End Sub

Private Sub Text1_KeyPress(KeyAscii As Integer)
 MsgBox "KeyAscii = " & KeyAscii, , "Text1_KeyPress"
End Sub

-----------------[End of Code] -----------------------------------------------------------------

P.S.
  The advantage of KeyDown event is that it can detect the Navigation keys, such as
  the PageUp, PageDown, Home, End keys. It can also detect the Delete and Back Space
  and the Function keys.
0

Featured Post

Technology Partners: 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

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month15 days, 6 hours left to enroll

770 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