PDA

Click to See Complete Forum and Search --> : KeyPress


spandex44
Jan 21st, 2000, 10:55 PM
Hi,
I did a test to see how the KeyPress function works. To test it, I used this:

Private Sub Form_KeyPress(Enter As Integer)
Beep
End Sub

But when I press enter, nothing happens. How would I get it to work. Also, how would I use the arrow buttons?
Thanks.

QWERTY
Jan 22nd, 2000, 12:10 AM
Did you change Form's KeyPreview to True?
HTH

------------------
Visual Basic Programmer
------------------
PolComSoft
You will hear a lot about it.

spandex44
Jan 22nd, 2000, 12:19 AM
Ok, thanks a lot! It works now. What does changing the value of KeyPreview do? Thanks.

Jan 22nd, 2000, 12:21 AM
You could also use KeyAscii instead of KeyCode

Juan Carlos Rey
Jan 22nd, 2000, 08:40 AM
Makes the Key events (Keypress, KeyUp and KeyDown) go to the form instead of to any control.

[This message has been edited by Juan Carlos Rey (edited 01-22-2000).]

Jan 22nd, 2000, 11:06 AM
i think you'll find it is supposed to be (keyascii as integer) instead of enter. thy that first.

if you need the arrow keys:

form1_keydown(Keycode as Integer, shift as integer)
if keycode = vbkeyLeft then 'do stuff for left arrow
etc...


[This message has been edited by wossname (edited 01-22-2000).]

DiGiTaIErRoR
Jan 22nd, 2000, 11:11 AM
Or use the ASC reference;
A=65
B=66
so:

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = 65 Then MsgBox "A"
If KeyCode = 66 Then MsgBox "B"
End Sub

NOTE: It ignores 'case' A or a B or B either activate the code!

------------------
DiGiTaIErRoR

spandex44
Jan 22nd, 2000, 11:46 AM
Thanks both of you, but it still doesn't work. I tried both ways, but nothing happens when I press the buttons. I also tried the same with the KeyPress function.
Thanks for the help.

------------------
Regards,
Alexander McAndrew
VB Zone
http://gsenterprise.server101.com