Results 1 to 4 of 4

Thread: GetAsyncKeyState problem *resolved*

  1. #1

    Thread Starter
    New Member
    Join Date
    Sep 2003
    Posts
    8

    GetAsyncKeyState problem *resolved*

    I am working on the game pong. I cannont get my paddle to move up and down. I think there is more than one problem with my code, but I know that I must be using GetAsyncKeyState incorrectly because it doesn't change the values. Here is my code.

    VB Code:
    1. Private Sub Main()
    2.     lngTick = GetTickCount
    3.    
    4.     Do While blnGameLoop
    5.         lstTick = GetTickCount
    6.    
    7.         If lstTick - lngTick >= 50 Then
    8.            
    9.             movepaddle
    10.            
    11.             BitBlt frmPong.hDC, 0, 0, Picture1.Width, Picture1.Height, Picture1.hDC, 0, 0, SRCCOPY
    12.            
    13.             BitBlt frmPong.hDC, x, y, 32, 89, Picture2.hDC, 34, 0 ,SRCAND
    14.            
    15.             BitBlt frmPong.hDC, x, y, 33, 89, Picture2.hDC, 0, 0, SRCPAINT
    16.            
    17.          
    18.           DoEvents
    19.           lngTick = GetTickCount
    20.         End If
    21.    
    22.     Loop
    23. End Sub
    24.  
    25.  
    26. Private Sub movepaddle()
    27.             If (GetAsyncKeyState(vbKeyUp)) = True Then
    28.                     y = y - 10
    29.             End If
    30.            
    31.             If (GetAsyncKeyState(vbKeyDown)) = True Then
    32.                     y = y + 10
    33.             End If
    34. End Sub
    Last edited by 0wnd; Sep 29th, 2003 at 08:42 PM.

  2. #2

  3. #3

    Thread Starter
    New Member
    Join Date
    Sep 2003
    Posts
    8
    Hmm, I tried the code they had, and it doesn't work. The value of y is not changing. This is what I changed the code to.

    VB Code:
    1. Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
    2.     Keys(KeyCode) = True
    3. End Sub
    4.  
    5. Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer)
    6.     Keys(KeyCode) = False
    7. End Sub
    8.  
    9. Private Sub movepaddle()
    10.     If Keys(38) = True Then 'I also tried vbKeyUp instead of 38
    11.         y = y - 10
    12.     End If
    13.    
    14.     If Keys(40) = True Then 'I also tried vbKeyDown instead of 40
    15.         y = y + 10
    16.     End If
    17. End Sub

  4. #4
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190
    Do you have the KeyPreview property of your form set to true???

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