SendKeys after every 5 minutes to stop screen saver to occur

aman

Registered User.
Local time
Today, 12:59
Joined
Oct 16, 2008
Messages
1,251
Hi All
I am writing the folliowing piece of code to be called again and again after 30 min. But I need to do invisible mouse move to stop screen saver occuring so i want to sendkeys after every 5 minutes. The Sub abc is in module and everything works except stoping screensaver from occuring .Can anyone please tell me the way to do it?
Code:
Private Sub UserForm_Initialize()
'Update the Barcodes printed today
        Call CommandButton1_Click
        'Update batches to be scanned / batches scanned today
        Call CommandButton3_Click
        'Update files batched and counted today
        Call CommandButton2_Click
 Application.OnTime Now + TimeValue("00:00:00"), "abc"
        'GoToSub
End Sub
Sub abc()
'Update the Barcodes printed today
        Call DashBoardUF1.CommandButton1_Click
        'Update batches to be scanned / batches scanned today
        Call DashBoardUF1.CommandButton3_Click
        'Update files batched and counted today
        Call DashBoardUF1.CommandButton2_Click
 SendKeys "%FO"
 Application.OnTime Now + TimeValue("00:00:05"), "abc"
        'GoToSub
End Sub
 
I tried the following code but still screen saver appears after couple of minutes :( The following functions are present in module.
Code:
Sub abc()
'Update the Barcodes printed today
        Call DashBoardUF1.CommandButton1_Click
        'Update batches to be scanned / batches scanned today
        Call DashBoardUF1.CommandButton3_Click
        'Update files batched and counted today
        Call DashBoardUF1.CommandButton2_Click
        'Application.Wait Now + TimeValue("00:01:00")
        'SendKeys "{Enter}", False
       alertTime = Now + TimeValue("00:01:00")
       Application.OnTime alertTime, "SendKeysFunc"
       Application.OnTime Now + TimeValue("00:30:00"), "abc"
        'GoToSub
End Sub
Sub SendKeysFunc()
alertTime = Now + TimeValue("00:01:00")
Application.OnTime alertTime, "SendKeysFunc"
End Sub
 
Why not just turn the screen saver off?
 
JHB, I am not allowed to do that. I just need to do press any key automatically or move mouse after every couple of minutes using vba. Can you please help me in this?
 
Sorry - but I can't see any differers between stop Screen saver to appear when you open you application and send a key press every 5 minutes for keeping Screen saver from appearing.
 
Thanks JHB, so how can I turn screen saver off using vba when the application is opened and then turn the screen saver back on when the application gets closed. Thanks
 
Code found by using Google.
Place the code in a Module:
Code:
Private Const SPI_SETSCREENSAVEACTIVE = 17
 
Private Declare Function SystemParametersInfo Lib "user32" _
Alias "SystemParametersInfoA" (ByVal uAction As Long, _
ByVal uParam As Long, ByVal lpvParam As Long, _
ByVal fuWinIni As Long) As Long
 
Public Function EnableScreenSaver(ByVal bStatus As Boolean) As Boolean
    Dim lActiveFlag As Long
    Dim lRetval      As Long
     
    lActiveFlag = IIf(bStatus, 1, 0)
    lRetval = SystemParametersInfo(SPI_SETSCREENSAVEACTIVE, lActiveFlag, 0, 0)
     
    If lRetval > 0 Then
        EnableScreenSaver = True
    Else
        EnableScreenSaver = False
    End If
     
End Function
If you open a form when you application is open then place the below line in the form's open event:
Code:
Call EnableScreenSaver(False)
And the line in the form's close event:
Code:
Call EnableScreenSaver(True)
 
JHB, I have tried that code but still screen saver is turning on. :(
 
If there is a group policy enforced on a domain it's quite possible this won't work.

Guessing that this is going on a wallboard / TV display or similar you may want to investigate creating a intranet style web page to present the information ? Or possibly as SSRS report if you have SQL server available?

It won't stop the screen saver though if it's presented on a domain policy controlled display...
 
I works by me - I'm running Windows 8.
Are you sure the code got run? Are you calling it with parameter set to false?
 
Thanks Minty, My company is not using sql server so cant use SSRS Report.

Can I use something like SendKeys function to press a key automatically using vba after every couple of minutes. I think this should be possible.

ANy advice will be much appreciated.
 
What does it mean when you say you can't turn the screen saver off.

What are your full instructions in this regard.
 
I works by me - I'm running Windows 8.
Are you sure the code got run? Are you calling it with parameter set to false?

JHB, I'm running Windows XP and yes sure the code got run as I put "Hello" message in the function and it appeared when I run the code.

But unfortunately i can't turn off the screen saver. I want to keep on looking the progress on the dashboard I built and doesn't want the screen to go blank..

Thanks and hope you can help me to sort out my problem.
 
RainLover, I think you got my answer in the above post.

Please guys help me out. Thanks All
 
The problem you have is that send keys only imitates the effective key press within Access, but it is not actually a keystroke or mouse move. Therefore the OS still is unaware that a key is pressed.
 
JHB, I'm running Windows XP and yes sure the code got run as I put "Hello" message in the function and it appeared when I run the code.

But unfortunately i can't turn off the screen saver.
Only for following up, just checked on a computer with XP, and it works there to.
I want to keep on looking the progress on the dashboard I built and doesn't want the screen to go blank..
It is you right to choose what you want - good luck. :)
 
Thankfully, never had any such issues nor did I have to turn off the screensaver. Flip Clocker works butter smooth and gives an aesthetic look to my mac.
flipclocker.com
 
@aman

The problem is that the screen-saver isn't an Access function, it's a Windows function governed from the power management "Settings" screen. My initial research says this is part of the registry under HKEY_USERS\DEFAULT\Control Panel\Desktop\... which means it is a registry setting that most programs will not be allowed to access unless the user could manually get to it.

If you are not allowed to turn off your screen saver then it is probably set by group policy to be "off limits" - and that means you can't turn it off manually OR by program. Screen savers are sensitive to either mouse movement/clicks or keyboard clicks - neither of which you can generate from Access because you can't generate outputs to an input-only device. In a tightly restricted environment, what you request might not be possible.
 
Yep, fell for it because someone else awakened the thread. Sometimes I'm asleep at the switch, particularly if I've just had a big meal. Postprandial stupor, I guess.
 

Users who are viewing this thread

Back
Top Bottom