Results 1 to 7 of 7

Thread: easy question that i should know...

  1. #1
    Guest

    Unhappy

    hello,

    i am wondering how to move the mouse with the click of a button,
    or a timer. ive looked through the tutorials and i always
    get errors whenever i try to put the declarations in. please help quickly, thanks


  2. #2
    Guest
    To move the mouse, use the SetCursorPos api function.

    Code:
    Private Sub Command1_Click()
    Dim t&
    t& = SetCursorPos(500,300)
    End Sub

  3. #3
    Guest
    ok,

    it told me that the setcursorpos was undefined.

    -thanks in advance

  4. #4
    Guest
    Oops, it would help if I gave you the api function along with it .

    Code:
    Declare Function SetCursorPos Lib "user32" (ByVal x _
    As Long, ByVal y As Long) As Long

  5. #5
    Guest
    If you're using it in a Form, it should be
    Code:
    Private Declare Function SetCursorPos Lib "user32" (ByVal x As Long, ByVal y As Long) As Long
    Otherwise, you must place it in a Module.

  6. #6
    Guest
    thanks megatron,

    i needed the private thing in front. but heres another question for you, how do make it move to keep the screen saver at bay?

  7. #7
    Guest
    Simply use a Timer to keep changing the cursor position.

    Add the following to a form with a Timer.
    Code:
    Private Declare Function SetCursorPos Lib "user32" (ByVal x As Long, ByVal y As Long) As Long
    
    Private Sub Form_Load()
        Timer1.Interval = 1000
    End Sub
    
    Private Sub Timer1_Timer()
        'Move the Cursor in random places
        Randomize
        SetCursorPos Int(Rnd * 200) + 1, Int(Rnd * 200) + 1
    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