Results 1 to 5 of 5

Thread: hELP tO MOVE MOUSE

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jan 1999
    Posts
    118

    Lightbulb

    I am trying to move the mouse randomly and then have the program to quit moving when I press the shift key. Could anyone give me some examples?

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

    SetCursorPos + ShowCursor + GetKeyState API

    Just call the following API function will do.
    • SetCursorPos
    • ShowCursor
    • GetKeyState



    Code:
    Option Explicit
    Private Declare Function SetCursorPos Lib "user32" (ByVal x As Long, ByVal y As Long) As Long
    Private Declare Function ShowCursor Lib "user32" (ByVal bShow As Long) As Long
    Private Declare Function GetKeyState Lib "user32" (ByVal nVirtKey As Long) As Integer
    
    Private Const VK_LSHIFT = &HA0 'Left SHIFT Key
    Private Const VK_RSHIFT = &HA1 'Right SHIFT Key
    
    Private MyX As Long
    Private MyY As Long
    
    Private Sub Form_Load()
    Timer1.Enabled = True
    End Sub
    
    Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
    End
    End Sub
    
    Private Sub Timer1_Timer()
    Randomize 255
    MyX = CLng((Rnd * (Screen.Width / 25)) + 1)
    MyY = CLng((Rnd * (Screen.Height / 25)) + 1)
    
    SetCursorPos MyX, MyY
    ShowCursor True
    
    If GetKeyState(VK_LSHIFT) <> 0 Then Timer1.Enabled = False
    End Sub
    [Edited by Chris on 06-15-2000 at 08:06 PM]

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jan 1999
    Posts
    118
    Everything works except the shift key.It still wont stop the program.
    Thanks for any information.

  4. #4
    Guest
    Use the GetAsyncKeyState.

    Code:
    If GetAsyncKeyState(vbKeyShift) Then Timer1.Enabled = True

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

    Lightbulb

    Originally posted by paul
    Everything works except the shift key.It still wont stop the program.
    Thanks for any information.
    If you want to exit the program, then just pur an "End" at the the Timer1_Timer() events
    Code:
    Private Sub Timer1_Timer() 
      :
      :
      If GetKeyState(VK_LSHIFT) <> 0 Then End
    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