PDA

Click to See Complete Forum and Search --> : Key press


Motoxpro
Nov 15th, 2001, 11:20 PM
how do i know what key was pressed

Motoxpro
Nov 16th, 2001, 12:56 PM
so i have to set the ascii value?

steve65
Nov 16th, 2001, 12:58 PM
You can also use VBs constants

Sub Form1_KeyPress(KeyAscii As Integer)
'KeyAscii is the ascii code of the key pressed
If KeyAscii = vbCR Then
KeyAscii = 0 ' prevent ascii 13 from getting In To the program
End If
End Sub

Motoxpro
Nov 16th, 2001, 01:47 PM
so sayi wanted it to do something when "I" was press i could put


Sub Form1_KeyPress(KeyAscii As Integer)
'KeyAscii is the ascii code of the key pressed
If KeyAscii = vbI Then
KeyAscii = 0 ' prevent ascii 13 from getting In To the program
End If
End Sub

steve65
Nov 20th, 2001, 06:18 AM
Sorry it took so long to get back to you

Sub Form1_KeyPress(KeyAscii As Integer)
'KeyAscii is the ascii code of the key pressed
If KeyAscii = vbKeyI Then
KeyAscii = 0 ' prevent ascii 13 from getting In To the program
End If
End Sub

Motoxpro
Nov 20th, 2001, 10:47 AM
oo ok...just 1 more thing if i wanted it to do somethin when the key was press could i d like this?

Sub Form1_KeyPress(KeyAscii As Integer)
'KeyAscii is the ascii code of the key pressed
If KeyAscii = vbKeyI Then
KeyAscii = 0 ' prevent ascii 13 from getting In To the program
'Dothis......and i would put my code right here?
End If
End Sub

steve65
Nov 20th, 2001, 10:58 AM
What I do is place my code in a sub and then run that.

Sub Form1_KeyPress(KeyAscii As Integer)
'KeyAscii is the ascii code of the key pressed
If KeyAscii = vbKeyI Then
RunSub
End If
End Sub

Motoxpro
Nov 20th, 2001, 12:38 PM
thanks alot steve :)

sql_lall
Nov 21st, 2001, 03:24 AM
Whenever I use KeyPress, there is alsways some picture/ button somewhere that doesn't allow me to use form1_KeyPress.
Is there any way of doing something like
Global_KeyPress?? Where, no matter what object is selected, the keypress still does stuff??
I.e. I made a game, that u used the keyboard to move around in... but i used a frame and picture. So I had to use Form1_KeyPress , BUT when I compiled + used it on another computer, I had to add picture1_Keypress :confused:

magoochris
Nov 21st, 2001, 04:01 AM
I use key down


Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyLeft Then 'looks for the left arrow
img1.Left = img1.Left - 20 'moves img1 20 to the left
End If
End Sub