-
Hi.
Imagine a blue screen... A ball bouncing back and
forth across the screen. The ball to your eyes doesnt
have the same color as the back round.. you can see it perfectly.
Now for a little information. This ball is not in my program. Its in another window just being drawn on.
Q: Say your hand isnt on the mouse. And you want to make a program that directs the cursor to follow the ball around. So where ever the ball goes... The cursor would be in the middle of the ball.
How would you do this?
-
hi, This isn't called AI its called 'moving the mouse'
try this link:
http://www.vb-world.net/mouse/tip15.html
-
Noooo.
I want to have the program FOLLOW the
ball. (Like it needs to find the color change and
then find the middle and then put the mouse in it)
-
Use the api GetPixel in a loop to catch color change in the ball. Once you place your cursor at the centre of the ball initially, constantly check for the movement of hte ball by checking co-ordintes which are a few pixel away from the perimeter of the ball. Tis will tell us the directon in which the ball is goimg. Move your cursor accordingly ot keep in the centre of the ball
-
Use the SetCursorPos function in a Timer, so that it updates regularly.
Code:
Private Declare Function SetCursorPos Lib "user32" Alias "SetCursorPos" (ByVal x As Long, ByVal y As Long) As Long
Private Sub Timer1_Timer()
SetCursorPos (BallWidth / 2) + Me.Width, (BallHeight / 2) + Me.Height
End Sub
-
Optimal scan
If you start searching for the ball, and it's small, it might take time. But if you go trough the screen in more detail everytime you do the scan, you could find the ball very fast.
Have 3 nested loops, in innermost for x axis, second for y and third for resolution. Both inner loops should start from resolution\2 and resolution should start with the smaller from screen width/height divided by 2. The inner loops should be for next type and step trough resolution and the other one should be a do while resolution>=ballradius. and resolution should be halved each time.