Solved

Keydown Event (Keycode)

Posted on 2002-07-01
8
1,477 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
 

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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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 69

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

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…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
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…

914 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now