Solved

Keydown Event (Keycode)

Posted on 2002-07-01
8
1,483 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
8 Comments
 
LVL 142

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
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 

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

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
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…
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…

832 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