Autohotkey Screensaver only works on main screen, need to work on extra screen Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
maxkill
Posts: 158
Joined: 11 Apr 2016, 13:03

Autohotkey Screensaver only works on main screen, need to work on extra screen

29 Dec 2022, 10:50

viewtopic.php?f=76&t=112067&p=498835#p498835
(Script to keep a static ish video or image moving about slitghtly randomly on one screen to avoid burnin.)

Code: Select all

#Requires AutoHotkey v1
offset := 100                                  ; Distance (pixels) to move the window
freq   := 60000 * MINS := 10                   ; Frequency of moving the window
monNum :=   3                                  ; Monitor number
down   :=  -1
SysGet, mon, MonitorWorkArea, monNum           ; Get the monitor's working area
Process, Priority,, B
MsgBox, 64, Instructions, Press CTRL-F3 to select the active window to move

^F3::                                          ; CTRL-F3 = Select the window to move
WinGetActiveTitle, title
wTitle := "ahk_id" WinActive("A")              ; Define the WinTitle
MsgBox, 64, Window, Your window is:`n`n%title%
SetTimer, Move, % freq
Return

Move:
If WinExist(wTitle) {
 SoundBeep, 1900
 down := -down
 WinGetPos, x, y, w, h
 x += down * offset
 y += down * offset
 (x + w > monRight ) && x := monRight  - w
 (x     < monLeft  ) && x := monLeft
 (y + h > monBottom) && y := monBottom - h
 (y     < monTop   ) && y := monTop
 (x + w > monRight ) && w := monRight  - x
 (y + h > monBottom) && h := monBottom - y
 WinRestore
 WinMove,,, x, y, w, h
} Else {
 SetTimer,, Off
 SoundBeep, 1000
}
Return
The script works great but not on intended monitor which is in my case the 3rd monitor. It defaults and moves the window to main screen instead of the intended one despite having the
monNum := 3

Can someone shed some light on what might be the issue? Would be great to get this working on correct screen.
User avatar
rommmcek
Posts: 1480
Joined: 15 Aug 2014, 15:18

Re: Autohotkey Screensaver only works on main screen, need to work on extra screen

29 Dec 2022, 14:47

Show physical disposition of your monitors e.g. see pic.
Attachments
ThreeMonitors.png
ThreeMonitors.png (13.68 KiB) Viewed 575 times
maxkill
Posts: 158
Joined: 11 Apr 2016, 13:03

Re: Autohotkey Screensaver only works on main screen, need to work on extra screen

29 Dec 2022, 18:34

rommmcek wrote:
29 Dec 2022, 14:47
Show physical disposition of your monitors e.g. see pic.
Yes certainly I hope you mean this Image
Image
https://ibb.co/fGYh52z
can you see image?

My main screen is 2
Attachments
image.png
image.png (4.64 KiB) Viewed 551 times
User avatar
rommmcek
Posts: 1480
Joined: 15 Aug 2014, 15:18

Re: Autohotkey Screensaver only works on main screen, need to work on extra screen

30 Dec 2022, 03:36

Can't seem to find any flaw in the code.
Can you describe how it works for you and what does not work as expected.
maxkill wrote:
29 Dec 2022, 18:34
My main screen is 2
What do you mean by "My main screen is 2"? Your " screen 1" is still on the far right, isn't it?
Run this script and make 3 times "PrintScreen" when MsgBox tells you so and post pics.
Spoiler
maxkill
Posts: 158
Joined: 11 Apr 2016, 13:03

Re: Autohotkey Screensaver only works on main screen, need to work on extra screen

30 Dec 2022, 09:26

rommmcek wrote:
30 Dec 2022, 03:36
Can't seem to find any flaw in the code.
Can you describe how it works for you and what does not work as expected.
maxkill wrote:
29 Dec 2022, 18:34
My main screen is 2
What do you mean by "My main screen is 2"? Your " screen 1" is still on the far right, isn't it?
Run this script and make 3 times "PrintScreen" when MsgBox tells you so and post pics.
Spoiler
Your code made it work almost perfect even in this state it's useful!

Code: Select all

;#SingleInstance Force
;#Requires AutoHotkey v1
offset := 100                                  ; Distance (pixels) to move the window
freq   :=60000 * MINS := 10                   ; Frequency of moving the window
monNum :=   3                                  ; Monitor number
down   :=  -1
SysGet, mon1, MonitorWorkArea, 1           ; Get the monitor's working area
SysGet, mon2, MonitorWorkArea, 2           ; Get the monitor's working area
SysGet, mon3, MonitorWorkArea, 3           ; Get the monitor's working area

Process, Priority,, B
MsgBox, 64, Instructions, Press CTRL-F3 to select the active window to move

^F3::                                          ; CTRL-F3 = Select the window to move
WinGetActiveTitle, title
wTitle := "ahk_id" WinActive("A")              ; Define the WinTitle
MsgBox, 64, Window, Your window is:`n`n%title%
SetTimer, Move, % freq
Return

Move:
If WinExist(wTitle) {
 ;SoundBeep, 1900
 down := -down
 WinGetPos, x, y, w, h
 x += down * offset
 y += down * offset
 (x + w > mon3Right ) && x := mon3Right  - w
 (x     < mon3Left  ) && x := mon3Left
 (y + h > mon3Bottom) && y := mon3Bottom - h
 (y     < mon3Top   ) && y := mon3Top
 (x + w > mon3Right ) && w := mon3Right  - x
 (y + h > mon3Bottom) && h := mon3Bottom - y

 ;       . x ", " y "`n" w ", " h

 WinRestore
 WinMove,,, x, y, w, h
} Else {
 SetTimer,, Off
; SoundBeep, 1000
}
Return
The only thing is that it only moves the window back and forth between 2 positions (in correct screen 3), so the random movements are not there. Any idea why it's not moving randomly now?
User avatar
rommmcek
Posts: 1480
Joined: 15 Aug 2014, 15:18

Re: Autohotkey Screensaver only works on main screen, need to work on extra screen  Topic is solved

30 Dec 2022, 12:59

I didn't change the code! Use this Move instead:

Code: Select all

Move:
If WinExist(wTitle) {
 SoundBeep, 1900
 WinGetPos,,, w, h
 Random, x, mon3Left, mon3Right-w
 Random, y, mon3Top, mon3Bottom-h     
 WinRestore
 WinMove,,, x, y, w, h
} Else {
 SetTimer,, Off
 SoundBeep, 1000
}
Return
maxkill
Posts: 158
Joined: 11 Apr 2016, 13:03

Re: Autohotkey Screensaver only works on main screen, need to work on extra screen

30 Dec 2022, 13:23

rommmcek wrote:
30 Dec 2022, 12:59
I didn't change the code! Use this Move instead:

Code: Select all

code
You added the 3 after all the mon and also the other 2 sysget, but other than that no however that did the trick!

Thanks a bunch for solving the last piece of this and also to the original codemaker mikeyww! This will come in handy!

Here is the final screensaver script without the beeps,
simply change the monNum at top and all the mon numbers to your monitor aswell:

Code: Select all

#SingleInstance Force
;#Requires AutoHotkey v1
offset := 50                                  ; Distance (pixels) to move the window
freq   := 60000 * MINS := 1                   ; Frequency of moving the window
monNum :=   3                                  ; Monitor number
down   :=  -1
SysGet, mon1, MonitorWorkArea, 1           ; Get the monitor's working area
SysGet, mon2, MonitorWorkArea, 2           ; Get the monitor's working area
SysGet, mon3, MonitorWorkArea, 3           ; Get the monitor's working area

Process, Priority,, B
MsgBox, 64, Instructions, Press CTRL-F3 to select the active window to move

^F3::                                          ; CTRL-F3 = Select the window to move
WinGetActiveTitle, title
wTitle := "ahk_id" WinActive("A")              ; Define the WinTitle
MsgBox, 64, Window, Your window is:`n`n%title%
SetTimer, Move, % freq
Return

Move:
If WinExist(wTitle) {
; SoundBeep, 1900
 WinGetPos,,, w, h
 Random, x, mon3Left, mon3Right-w
 Random, y, mon3Top, mon3Bottom-h     
 WinRestore
 WinMove,,, x, y, w, h
} Else {
 SetTimer,, Off
; SoundBeep, 1000
}
Return

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Bing [Bot], Google [Bot], labrint and 192 guests