simulate left mouse click every 60 seconds

keith0528

Active Member
Joined
Apr 23, 2009
Messages
250
Greetings VBA guru's,

I'm trying to keep my computer active when i go to lunch. Can vba simulate a click event every 30 or 60 seconds?


thanks in advance,

K
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
Why not instead just change your standby settings?
 
Upvote 0
Ok, so i take it no one knows how to do that. I'll keep digging around for code online.

thanks anyway.

Keith
 
Upvote 0
a google for
keep awake windows
produced, among others:
Caffeine
http://www.zhornsoftware.co.uk/caffeine/index.html
Stims - Keep Windows Awake | ACAPsoft - For software As Compact As Possible
http://acapsoft.com/det.php?prog=Stims
Stay-awake utility for Windows Vista and 7 (C#)
http://www.808.dk/?code-csharp-stay-awake
Download Stay Awake 1.0 Free - Prevent sleep or hibernate mode, allowing tasks to be carried out without interruption - Softpedia
http://www.softpedia.com/get/Tweak/System-Tweak/Stay-Awake.shtml
Computer does not stay awake for scheduled task - Microsoft Answers
http://answers.microsoft.com/en-us/...led-task/8a5acf64-bddc-4539-9dc5-4b3cab43cfb9

I don't vouch for these, never tried them, onus is on you to check their malware status.
 
Upvote 0
All - thanks for your responses,

I've pieced together what I was looking for. The below code will click on a spot on the screen that you designate with coordinates every x seconds. It works beautifully.

All I need now is to figure out the right syntax to stop the code.



Public Declare Function SetCursorPos Lib "user32" (ByVal x As Long, ByVal y As Long) As Long
Public Declare Sub mouse_event Lib "user32" (ByVal dwFlags As Long, ByVal dx As Long, ByVal dy As Long, ByVal cButtons As Long, ByVal dwExtraInfo As Long)
Public Const MOUSEEVENTF_LEFTDOWN = &H2
Public Const MOUSEEVENTF_LEFTUP = &H4
Dim TimerActive As Boolean

Sub KeepWindowsActive()
TimerActive = True
'move cursor and click
SetCursorPos 200, 200 'x and y position
mouse_event MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0
mouse_event MOUSEEVENTF_LEFTUP, 0, 0, 0, 0
Application.OnTime Now + TimeValue("00:00:10"), "KeepWindowsActive"

End Sub


Anyone know the correct way to stop it?

thanks,
Keith
 
Upvote 0
Try like:

<font face=Courier New><SPAN style="color:#00007F">Option</SPAN> <SPAN style="color:#00007F">Explicit</SPAN><br>    <br><SPAN style="color:#00007F">Dim</SPAN> dtmNextTime <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Date</SPAN><br>    <br><SPAN style="color:#00007F">Sub</SPAN> StartIt()<br>    <br>    dtmNextTime = Now + TimeValue("00:00:05")<br>    Application.OnTime dtmNextTime, "Recycle", , <SPAN style="color:#00007F">True</SPAN><br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN><br>    <br><SPAN style="color:#00007F">Sub</SPAN> StopIt()<br>    Application.OnTime dtmNextTime, "Recycle", , <SPAN style="color:#00007F">False</SPAN><br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN><br>    <br><SPAN style="color:#00007F">Sub</SPAN> Recycle()<br>    Range("A1") = Range("A1") + 1<br>    dtmNextTime = Now + TimeValue("00:00:05")<br>    Application.OnTime dtmNextTime, "Recycle", , <SPAN style="color:#00007F">True</SPAN><br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN></FONT>
 
Upvote 0

Forum statistics

Threads
1,218,243
Messages
6,141,351
Members
450,352
Latest member
lohpa

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top