Solved

problem with keypress VS keydown

Posted on 2004-09-29
6
1,228 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
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
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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 20 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

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…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

808 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