?
Solved

Keydown Event (Keycode)

Posted on 2002-07-01
8
Medium Priority
?
1,508 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 150 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…
Suggested Courses
Course of the Month15 days, 10 hours left to enroll

743 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