Solved

Keydown Event (Keycode)

Posted on 2002-07-01
8
1,494 Views
Last Modified: 2010-07-27
How can I suppress the Key pressed, so that it doesn't get printed in the textbox?

I tried

Keycode = 0

, but the key gets still printed. What can I do?

And the other thing is ...

How can I change a Keycode into the actual string value?

When I press "1" on the numbers (on the right) I get the value 96, that is actually "a" when I use Chr(96).


Thanks ...

BL
0
Comment
Question by:beni_luedi
[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
8 Comments
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 50 total points
ID: 7121384
You mess up the KeyCode and the KeyAscii values.

In the KeyDown and KeyUp, you have the KeyCode, where you can use the constants vbKey1 and vbKeyNumpad1 to check if "1" is pressed, while in the KeyPresses you get the ascii code which is always asc("1") ie 49

Thus:
Private Sub Text1_KeyPress(KeyAscii As Integer)
  If KeyAscii = asc("1") Then
    KeyAscii = 0
  End If
End Sub


CHeers
0
 
LVL 2

Expert Comment

by:priya_pbk
ID: 7121412
set the form's "KeyPreview" Property=True

-priya



0
 
LVL 2

Expert Comment

by:priya_pbk
ID: 7121431
Why do you want to convert the actual keycode into string value?

I mean if you use Asc(keyascii) or Asc(keycode) in any of the text events it will surely return the ascii code of the key pressed.

does that help?

-priya





0
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 

Expert Comment

by:Priestex
ID: 7121573
I am not sure what u mean by the keypress being supressed,
if u want to hide the text that is typed into a text area , u could use a mask and set the value to the space character.

This way when you enter data into the text area the cursor will advance forward without showing the data .

0
 
LVL 4

Expert Comment

by:trkcorp
ID: 7122132
Listen to angel, use the keypress events and set the ascii value to 0 to suppress keystrokes...  It is that simple.
0
 
LVL 2

Expert Comment

by:priya_pbk
ID: 7122614
that's true actually, but beni_luedi has already written the code for keyascii=0 or keycode=0.

What I feel is that beni_luedi has forgotten to set the Form's KeyPreview to True, which is important to catch the keystrokes on the form.

-priya
0
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 7122705
you need to set KeyCode = 0 into the KeyDown event of your control (not in the KeyUp event).
0
 

Author Comment

by:beni_luedi
ID: 7123512
Thanks for all the comments.

I just thourght I can set ...

Keycode = 0 in KeyDown event

to avoid a keystroke, but I have to use

Keyascii = 0 in the KeyPress event.

I will give points to the first comment.

Thanks anyway.

BL
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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 While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

687 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