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?
Printable View
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?
Just call the following API function will do.
- SetCursorPos
- ShowCursor
- GetKeyState
[Edited by Chris on 06-15-2000 at 08:06 PM]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
Everything works except the shift key.It still wont stop the program.
Thanks for any information.
Use the GetAsyncKeyState.
Code:If GetAsyncKeyState(vbKeyShift) Then Timer1.Enabled = True
If you want to exit the program, then just pur an "End" at the the Timer1_Timer() eventsQuote:
Originally posted by paul
Everything works except the shift key.It still wont stop the program.
Thanks for any information.
Code:Private Sub Timer1_Timer()
:
:
If GetKeyState(VK_LSHIFT) <> 0 Then End
End Sub