how do i know what key was pressed
Printable View
how do i know what key was pressed
so i have to set the ascii value?
You can also use VBs constants
Code: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
so sayi wanted it to do something when "I" was press i could put
VB Code:
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
Sorry it took so long to get back to you
Code: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
oo ok...just 1 more thing if i wanted it to do somethin when the key was press could i d like this?
VB Code:
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
What I do is place my code in a sub and then run that.
Code:Sub Form1_KeyPress(KeyAscii As Integer)
'KeyAscii is the ascii code of the key pressed
If KeyAscii = vbKeyI Then
RunSub
End If
End Sub
thanks alot steve :)
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:
I use key down
VB Code:
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