|
-
Nov 16th, 2001, 12:20 AM
#1
Thread Starter
Frenzied Member
Key press
how do i know what key was pressed
-
Nov 16th, 2001, 01:56 PM
#2
Thread Starter
Frenzied Member
so i have to set the ascii value?
-
Nov 16th, 2001, 01:58 PM
#3
Fanatic Member
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
-
Nov 16th, 2001, 02:47 PM
#4
Thread Starter
Frenzied Member
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
-
Nov 20th, 2001, 07:18 AM
#5
Fanatic Member
Actually...
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
-
Nov 20th, 2001, 11:47 AM
#6
Thread Starter
Frenzied Member
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
-
Nov 20th, 2001, 11:58 AM
#7
Fanatic Member
Sure
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
-
Nov 20th, 2001, 01:38 PM
#8
Thread Starter
Frenzied Member
thanks alot steve
-
Nov 21st, 2001, 04:24 AM
#9
Overall keypress
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
-
Nov 21st, 2001, 05:01 AM
#10
Lively Member
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|