Results 1 to 10 of 10

Thread: Key press

  1. #1

    Thread Starter
    Frenzied Member Motoxpro's Avatar
    Join Date
    Sep 2001
    Location
    Spiro, OK
    Posts
    1,211

    Key press

    how do i know what key was pressed

  2. #2

    Thread Starter
    Frenzied Member Motoxpro's Avatar
    Join Date
    Sep 2001
    Location
    Spiro, OK
    Posts
    1,211
    so i have to set the ascii value?

  3. #3
    Fanatic Member steve65's Avatar
    Join Date
    Jun 2000
    Posts
    610
    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
    This space for rent...

  4. #4

    Thread Starter
    Frenzied Member Motoxpro's Avatar
    Join Date
    Sep 2001
    Location
    Spiro, OK
    Posts
    1,211
    so sayi wanted it to do something when "I" was press i could put

    VB Code:
    1. Sub Form1_KeyPress(KeyAscii As Integer)
    2.           'KeyAscii is the ascii code of the key pressed
    3.           If KeyAscii = vbI Then
    4.                 KeyAscii = 0 ' prevent ascii 13 from getting In To the program
    5.            End If
    6. End Sub

  5. #5
    Fanatic Member steve65's Avatar
    Join Date
    Jun 2000
    Posts
    610

    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
    This space for rent...

  6. #6

    Thread Starter
    Frenzied Member Motoxpro's Avatar
    Join Date
    Sep 2001
    Location
    Spiro, OK
    Posts
    1,211
    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:
    1. Sub Form1_KeyPress(KeyAscii As Integer)
    2.           'KeyAscii is the ascii code of the key pressed
    3.           If KeyAscii = vbKeyI Then
    4.                 KeyAscii = 0 ' prevent ascii 13 from getting In To the program
    5. 'Dothis......and i would put my code right here?
    6.            End If
    7. End Sub

  7. #7
    Fanatic Member steve65's Avatar
    Join Date
    Jun 2000
    Posts
    610

    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
    This space for rent...

  8. #8

    Thread Starter
    Frenzied Member Motoxpro's Avatar
    Join Date
    Sep 2001
    Location
    Spiro, OK
    Posts
    1,211
    thanks alot steve

  9. #9
    sql_lall
    Guest

    Cool 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

  10. #10
    Lively Member magoochris's Avatar
    Join Date
    Nov 2001
    Location
    Australia
    Posts
    81
    I use key down

    VB Code:
    1. Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
    2.     If KeyCode = vbKeyLeft Then 'looks for the left arrow
    3.         img1.Left = img1.Left - 20 'moves img1 20 to the left
    4.     End If
    5. 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
  •  



Click Here to Expand Forum to Full Width