Results 1 to 6 of 6

Thread: ASCII

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jun 2000
    Posts
    21

    Unhappy

    Why doesn't this work???????
    i'm trying to get picture1 to move around the screen using the keyboard!!


    Private Sub Form_KeyPress(KeyAscii As Integer)
    If KeyAscii = Chr(104) Then Picture1.Left = Picture1.Left + 100
    If KeyAscii = Chr(107) Then Picture1.Left = Picture1.Left - 100
    If KeyAscii = Chr(117) Then Picture1.Top = Picture1.Top + 100
    If KeyAscii = Chr(109) Then Picture1.Top = Picture1.Top - 100
    End Sub


    Thanx

  2. #2
    Guest
    A better way of doing it is using the GetAsyncKeyState API.

    Code for module.

    Code:
    Declare Function GetAsyncKeyState Lib "user32" Alias "GetAsyncKeyState" (ByVal vKey As Long) As Integer
    Code for a Timer on the Form.

    Code:
    Privaye Sub Timer1_Timer()
    
       If GetAsyncKeyState(vbKeyUp) Then Pic1.Top = Pic1.Top - 100
       If GetAsyncKeyState(vbKeyDown) Then Pic1.Top = Pic1.Top + 100
       If GetAsyncKeyState(vbKeyLeft) Then Pic1.Left = Pic1.Left - 100
       If GetAsyncKeyState(vbKeyRight) Then Pic1.Left = Pic1.Left + 100
    End Sub

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Jun 2000
    Posts
    21

    Unhappy

    Yeh i know but it's for an assignment, and we have to have the use of ASCII conversions. is what u said using ASCII?

  4. #4
    Lively Member
    Join Date
    May 2000
    Posts
    67
    just put your form keypreview propriety at true.
    Code:
    Private Sub Form_KeyPress(KeyAscii As Integer) 
      If chr(KeyAscii) = "h" Then Picture1.Left = Picture1.Left + 100 
      If chr(KeyAscii) = "k" Then Picture1.Left = Picture1.Left - 100 
      If chr(KeyAscii) = "u" Then Picture1.Top = Picture1.Top + 100 
      If chr(KeyAscii) = "m" Then Picture1.Top = Picture1.Top - 100 
    End Sub
    Its not elegant but it work as you need it to.
    If possible please provide codes.
    Process by example is the best way to learn.

  5. #5
    PowerPoster Chris's Avatar
    Join Date
    Jan 1999
    Location
    K-PAX
    Posts
    3,238

    Lightbulb almost the samw question.

    It almost same as this Thread

  6. #6
    Guest
    The GetAsyncKeyState is more flexible than using the KeyPress or KeyDown event because this allows for multiple KeyDown's, Hence if you press DOWN and LEFT, the Picture will move diagonally, whereas if you do this with the KeyDown or KeyPress, it will just stop because 2 keys are pressed.

    Yes, this method is, in a sense, using ASCII because vbKeyUp and vbKeyDown etc. are all Constants for the actual ASCII value.

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