Run command to trigger screensaver?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
RDC
Posts: 112
Joined: 29 Jan 2023, 10:22

Run command to trigger screensaver?

23 Apr 2023, 08:31

Can anyone explain why this coding won't start my screensaver? When I trigger this script, it simply opens the settings menu for the screensaver. If I double click the same execution file (Helios.scr), it works fine.
And before anyone asks the always present question regarding screensavers... I run a screensaver simply because i think it looks cool and it provides a decent nightlight.

Code: Select all

#NoEnv
#Persistent
#SingleInstance, Force
;  ̶  ̶  ̶  ̶  ̶  ̶  ̶  ̶  ̶  ̶  ̶  ̶  ̶  ̶  ̶  ̶  ̶  ̶  ̶  ̶  ̶  ̶  ̶  ̶  ̶  ̶  ̶  ̶  ̶  ̶  ̶  ̶  ̶  ̶  ̶  ̶  ̶  ̶  ̶  ̶  ̶  ̶  ̶  ̶  
 Menu, Tray, Icon, wmploc.dll, 99 		 ; White Star tray Icon.
;  ̶  ̶  ̶  ̶  ̶  ̶  ̶  ̶  ̶  ̶  ̶  ̶  ̶  ̶  ̶  ̶  ̶  ̶  ̶  ̶  ̶  ̶  ̶  ̶  ̶  ̶  ̶  ̶  ̶  ̶  ̶  ̶  ̶  ̶  ̶  ̶  ̶  ̶  ̶  ̶  ̶  ̶  ̶  ̶  

^!T:: 	 ; (Ctrl+T)

Run, C:\Windows\System32\Helios.scr

RETURN
;  ̶  ̶  ̶  ̶  ̶  ̶  ̶  ̶  ̶  ̶  ̶  ̶  ̶ 
^!R::Reload
Home::
    Reload
^Esc::
     ExitApp
;  ̶  ̶  ̶  ̶  ̶  ̶  ̶  ̶  ̶  ̶  ̶  ̶  ̶
...the settings dialog that is already set the way I wanted.
image.png
image.png (9.67 KiB) Viewed 1159 times
User avatar
mikeyww
Posts: 27372
Joined: 09 Sep 2014, 18:38

Re: Run command to trigger screensaver?

23 Apr 2023, 08:40

I asked my friend Google to help you!

Code: Select all

#Requires AutoHotkey v1.1.33
saver := A_WinDir "\System32\scrnsave.scr"

F3:: ; https://learn.microsoft.com/en-us/troubleshoot/windows/win32/screen-saver-command-line
Run % saver " /s"
Return
User avatar
RDC
Posts: 112
Joined: 29 Jan 2023, 10:22

Re: Run command to trigger screensaver?

23 Apr 2023, 09:13

As always, thank you mikey!!
I should have known by now to remember about directories such as A_WinDir considering I have SetWorkingDir %A_ScriptDir% defaulted in all new scripts partly as a reminder.
And now I know about the /s , at least regarding this instance.
I skipped talking to your friend Google this time because they usually don't care much for my search terms.
Just checked in with them and what do you know... nothing but correct answers.
Have a great day and thanks again!!
User avatar
Xtra
Posts: 2750
Joined: 02 Oct 2015, 12:15

Re: Run command to trigger screensaver?

23 Apr 2023, 09:41

Another method:

Code: Select all

SendMessage, 0x112, 0xF140, 0,, Program Manager    ; 0x112 is WM_SYSCOMMAND -- 0xF140 is SC_SCREENSAVE
User avatar
RDC
Posts: 112
Joined: 29 Jan 2023, 10:22

Re: Run command to trigger screensaver?

23 Apr 2023, 10:17

Thank you @Xtra! This is a short and sweet one-liner.
You wouldn't know how to tweek this to select a non-default saver would you? Looking at the PostMessage/SendMessage page where this came from I'm not understanding if that's possible.
With the other method I just had to change scrnsave.scr to the specif saver's name such as Helios.scr making it easy to also add other screens if I wanted a quick change from my usual.
I don't see that happening too often, but just knowing what options exist is nice.
User avatar
Xtra
Posts: 2750
Joined: 02 Oct 2015, 12:15

Re: Run command to trigger screensaver?

23 Apr 2023, 16:53

If you want a screensaver other than what is set in windows, running the mikeyww example would better suit your needs.
User avatar
hced
Posts: 9
Joined: 11 Nov 2019, 13:30

Re: Run command to trigger screensaver?

14 Sep 2023, 14:35

Xtra wrote:
23 Apr 2023, 09:41
Another method:

Code: Select all

SendMessage, 0x112, 0xF140, 0,, Program Manager    ; 0x112 is WM_SYSCOMMAND -- 0xF140 is SC_SCREENSAVE
I couldn't get this to work with V2:

Code: Select all

#Requires AutoHotkey v2.0
#SingleInstance
#NoTrayIcon

; https://www.autohotkey.com/boards/viewtopic.php?p=518847&sid=a4146d6d8b33dcc3c0414d5ca98aa0b1#p518847
SendMessage(0x112, 0xF140, 0, , "Program Manager")    ; 0x112 is WM_SYSCOMMAND -- 0xF140 is SC_SCREENSAVE
Gives this error:

Code: Select all

Error: Function calls require a space or "(".  Use comma only between parameters.
Text:	SendMessage, 0x112, 0xF140, 0,, Program Manager
Any simple adjustment I need to make? I tried using an automatic converter and that gave this code but it doesn't do anything (I'm on Windows 11):

Code: Select all

#Requires AutoHotkey v2.0
#SingleInstance
#NoTrayIcon

; https://www.autohotkey.com/boards/viewtopic.php?p=518847&sid=a4146d6d8b33dcc3c0414d5ca98aa0b1#p518847
ErrorLevel := SendMessage(0x112, 0xF140, 0, , "Program Manager")    ; 0x112 is WM_SYSCOMMAND -- 0xF140 is SC_SCREENSAVE
Neither did this attempt of tweaking that automatic conversion-code:

Code: Select all

#Requires AutoHotkey v2.0
#SingleInstance
#NoTrayIcon

; https://www.autohotkey.com/boards/viewtopic.php?p=518847&sid=a4146d6d8b33dcc3c0414d5ca98aa0b1#p518847
SendMessage(0x112, 0xF140, 0, , "Program Manager")    ; 0x112 is WM_SYSCOMMAND -- 0xF140 is SC_SCREENSAVE

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: bobstoner289, Chunjee, macromint, peter_ahk and 326 guests