Solved

Keydown Event (Keycode)

Posted on 2002-07-01
8
1,471 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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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…

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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now