|
-
Jun 14th, 2000, 10:31 PM
#1
Thread Starter
Lively Member
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?
-
Jun 14th, 2000, 11:04 PM
#2
PowerPoster
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]
-
Jun 15th, 2000, 01:22 AM
#3
Thread Starter
Lively Member
Everything works except the shift key.It still wont stop the program.
Thanks for any information.
-
Jun 15th, 2000, 02:22 AM
#4
Use the GetAsyncKeyState.
Code:
If GetAsyncKeyState(vbKeyShift) Then Timer1.Enabled = True
-
Jun 15th, 2000, 07:27 AM
#5
PowerPoster
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|