473,407 Members | 2,315 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,407 software developers and data experts.

KeyPress Event

I'm trying to capture when a user presses a particular key (escape), so
I'm coding in the KeyPress event. Yet the code seems be bypassed
(breakpoint is never encountered). Should I be coding in a different
event? Is this a known issue? FYI, this is happening in both Access 97
and 2000.

Nov 12 '05 #1
8 37024
On Tue, 09 Sep 2003 17:20:52 GMT, William Ortenberg wrote:
I'm trying to capture when a user presses a particular key (escape), so
I'm coding in the KeyPress event. Yet the code seems be bypassed
(breakpoint is never encountered). Should I be coding in a different
event? Is this a known issue? FYI, this is happening in both Access 97
and 2000.


You have to set "KeyPreview" = true.

Also, you should know about the difference between KeyDown, KeyUp and
KeyPress. See OH.

HTH - Peter

--
No mails please.
This posting is provided AS IS with no warranties, and confers no rights.
Nov 12 '05 #2
William Ortenberg <bi*****@pacbell.net> wrote in message news:<UZ**************@newssvr29.news.prodigy.com> ...
I'm trying to capture when a user presses a particular key (escape), so
I'm coding in the KeyPress event. Yet the code seems be bypassed
(breakpoint is never encountered). Should I be coding in a different
event? Is this a known issue? FYI, this is happening in both Access 97
and 2000.

William,

The keypress-event does only respond to ANSI-characters and not to
non-text keys like escape, enter, cursor-keys, Home PgDn etc. The
effect of the shift-keys result in another character if valid. The
keyUp end KeyDown events however do respond to the escape-key and give
back a numeric value for each physical key with some exeptions and
conditions depending on the form-properties (see url
http://msdn.microsoft.com/library/de...acevtKeyUp.asp
etc)
Other than fhe keypress-event they also return the state of the shift,
control and alt-key states seperately.
see also the useful article
http://users.bigpond.net.au/abrowne1/ser-34.html

Marc
Nov 12 '05 #3
> The keypress-event does only respond to ANSI-characters and not to
non-text keys like escape, enter, cursor-keys, Home PgDn etc. ...


Try this:

Key Preview=Yes

Private Sub Form_KeyPress(KeyAscii As Integer)
If KeyAscii = vbKeyEscape Then
MsgBox "ESC pressed."
End If
End Sub
Peter

--
No mails please.
This posting is provided AS IS with no warranties, and confers no rights.
Nov 12 '05 #4
This is not correct. You should use the KeyDown event for this, not
KeyPress.
--
MichKa [MS]

This posting is provided "AS IS" with
no warranties, and confers no rights.
"Peter Doering" <ne**@doering.org> wrote in message
news:bj************@ID-204768.news.uni-berlin.de...
The keypress-event does only respond to ANSI-characters and not to
non-text keys like escape, enter, cursor-keys, Home PgDn etc. ...


Try this:

Key Preview=Yes

Private Sub Form_KeyPress(KeyAscii As Integer)
If KeyAscii = vbKeyEscape Then
MsgBox "ESC pressed."
End If
End Sub
Peter

--
No mails please.
This posting is provided AS IS with no warranties, and confers no rights.

Nov 12 '05 #5
> This is not correct. You should use the KeyDown event for this, not
KeyPress.


I know!

The statement was that KeyPress won't respond to ESC, but it does. I've
tested it.

Peter
Nov 12 '05 #6
The point is that it is foolish to rely on it, since apps will often trap
and remove the keystroke before it ever makes it to a WM_CHAR message (the
basis of the KeyPress event). Reliable code is always better....
--
MichKa [MS]

This posting is provided "AS IS" with
no warranties, and confers no rights.
"Peter Doering" <ne**@doering.org> wrote in message
news:bj************@ID-204768.news.uni-berlin.de...
This is not correct. You should use the KeyDown event for this, not
KeyPress.


I know!

The statement was that KeyPress won't respond to ESC, but it does. I've
tested it.

Peter

Nov 12 '05 #7
> The point is that it is foolish to rely on it, since apps will often trap
and remove the keystroke before it ever makes it to a WM_CHAR message (the
basis of the KeyPress event). Reliable code is always better....


Thanks. For common people who rely on OH this is not really obvious. Is
there a place where one can read about it?

When would you use KeyPress or KeyUp?

Peter

--
No mails please.
Nov 12 '05 #8
KeyDown and KeyUp are responding to WM_KEYDOWN and WM_KEYUP messages, and
KepPress resonds to a WM_CHAR message. The first to respond to physical
keystroke push/release, while the latter responds to when a message loop
asks Windows to translate that keystroke to a character.
--
MichKa [MS]

This posting is provided "AS IS" with
no warranties, and confers no rights.
"Peter Doering" <ne**@doering.org> wrote in message
news:bj************@ID-204768.news.uni-berlin.de...
The point is that it is foolish to rely on it, since apps will often trap and remove the keystroke before it ever makes it to a WM_CHAR message (the basis of the KeyPress event). Reliable code is always better....


Thanks. For common people who rely on OH this is not really obvious. Is
there a place where one can read about it?

When would you use KeyPress or KeyUp?

Peter

--
No mails please.

Nov 12 '05 #9

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

Similar topics

12
by: Trevor Fairchild | last post by:
I'm writing a program that is designed for quick navigation using specific buttons on the keyboard. In doing this, I have added a KeyPress event for every control on the form to intercept the key...
3
by: Darryn Ross | last post by:
Hi, I am trying to catch the KeyPress event on my datagrid but it isn't working... i have also tried registering the handler with the event like this... dgGLBatch.KeyPress += new...
3
by: Raul M. Colon | last post by:
Is possible to assign a click event to a button control in a Web form just pressing the return key? Something like windows forms where you can assign this action to a default control. For example,...
4
by: Tom | last post by:
I have a VB.NET user control that I wrote - this control has three or four other controls on it (textbox, combobox, datetime picker, etc). Now, whenever the control is on a form and the user enters...
3
by: Terry Olsen | last post by:
Is there anyway to cause a KeyPress event in a datagrid cell? The only way I get a keypress event is if none of the cells are selected. I was hoping to have the program respond to a certain...
3
by: Just Me | last post by:
I noticed that I don't get KeyDown nor KetPress events if NumLock is not on. I can probably find a workaround but it would be nice to know what the rules are. Can anyone tell me when KeyPress...
3
by: Nikolay Evseev | last post by:
Hi, I am trying to trace down the Enter key in my Form.KeyPress event handler. The KeyPreview property is set to false, so I'd assume that all key presses should go through my form's KeyPress...
7
by: Kay | last post by:
Hi all, I want to create a small function to monitor the keystroke. For example, if user key in a comma, I want to replace it with a single quote(etc)... In vb6 I an simply check the KeyAscii...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.