Page 1 of 1

Need help with pixel detection reaction

Posted: 07 Mar 2018, 00:58
by flamingonion
Hi guys, I'm new to ahk and trying to make a script that detects a pixel changes and terminate a process if that pixel has not changed for a certain amount of time. So far, it's been able to detect the pixel and terminate the process thatI wanted but there are 2 problems that I'm having right now.

[*]The script terminates itself after process termination (I worked around this but using Run but I'm sure there's a more elegant way to do this lol)
[*]The pixel that it detects may not be on the correct window, I guess its the static background window so it will kill the wanted process anyway regardless of pixel changes. (I tried different CoordMode but still, the problem remains)
Here's my script:

Code: Select all

CoordMode, Pixel, Relative ;<-- forces the Pixel commands to use relative mode
; this will cause the coordinates to move around based on what window is active
; and where the window is on the screen

;CoordMode, Pixel, Screen ;<-- forces the pixel commands to use the full screen.
; In this mode the coordinates will be locked to the entire screen area and whatever
; window is under that screen location will be used for the color comparison.

While (GetColor(thisColor) = GetColor(thatColor))
           continue

;Process,Close, vlc.exe
Run, "C:\Users\Bill\Desktop\script.exe"
Return

GetColor(X)
{
PixelGetColor, X, 351, 298
sleep 1000
Return X
}
Hope you guys can help me fix those 2 problems that I'm having, thank you and have a great day guys!

Re: Need help with pixel detection reaction

Posted: 07 Mar 2018, 03:07
by Blackholyman
to keep the script running https://autohotkey.com/docs/commands/_Persistent.htm

how about using a timer insted og your while loop? https://autohotkey.com/docs/commands/SetTimer.htm

something like this

Code: Select all

SetTimer, checkVlcpixel, 250
return

checkVlcpixel:
if (GetColor(thisColor) != GetColor(thatColor))
    Process,Close, vlc.exe
return
the way that the buildin commands work are that the window needs to be visible on the screen and the coordmode needs to be set to what works for your use case, so if you keep the vlc window as the active one the pixel check will work but if you change to some other window while the check is running the pixel it checks will change as the coords are Relative to the window your have active... the scrren option will work only if you allways keep the vlc window in the exact same place every time without any other window covering it...

Re: Need help with pixel detection reaction

Posted: 07 Mar 2018, 11:32
by flamingonion
Blackholyman wrote:to keep the script running https://autohotkey.com/docs/commands/_Persistent.htm

how about using a timer insted og your while loop? https://autohotkey.com/docs/commands/SetTimer.htm

something like this

Code: Select all

SetTimer, checkVlcpixel, 250
return

checkVlcpixel:
if (GetColor(thisColor) != GetColor(thatColor))
    Process,Close, vlc.exe
return
the way that the buildin commands work are that the window needs to be visible on the screen and the coordmode needs to be set to what works for your use case, so if you keep the vlc window as the active one the pixel check will work but if you change to some other window while the check is running the pixel it checks will change as the coords are Relative to the window your have active... the scrren option will work only if you allways keep the vlc window in the exact same place every time without any other window covering it...
Thank you for the great advice about the timer!
I understand the screen and relative modes, I tried both, however, the pixel detection still works as if the same pixel is there. Can it be other factors? or am I missing something? thank you Blackholyman!

Re: Need help with pixel detection reaction

Posted: 07 Mar 2018, 11:53
by BoBo
@flamingonion
what is your final target? To close vlc in a more reliable way once a video recording has finished?

Re: Need help with pixel detection reaction

Posted: 07 Mar 2018, 19:26
by flamingonion
BoBo wrote:@flamingonion
what is your final target? To close vlc in a more reliable way once a video recording has finished?
Hi Bobo,
My company has a series of TV used for advertising, running VLC from a PC host and occasionally it crashes, pops up errors, or worse, the sound still playing but the video stop. And sometimes it's not just the vlc, other applications also hang like this (but not totally unresponding). So I want a way to visually detect if the application is frozen and restart it reliably.

Re: Need help with pixel detection reaction

Posted: 07 Mar 2018, 21:42
by BoBo
[brainfart]
What about the process' load once the application gets frozen? If that value remains static (what I guess wouldn't be common for a running video instance) it might make sense to send an alert/reload the stream.
The problem I see, once the box gets frozen a monitoring script (if hosted on the same box) could get impacted as well. Have you logged already if that behaviour is occuring in a specific (run)timeframe??

What about to record the stream while playing it, so it should get obvious that the output file won't increase if the app is hanging ...
[/brainfart]

Re: Need help with pixel detection reaction

Posted: 08 Mar 2018, 02:34
by Blackholyman
also to what @BoBo said there is a VLC http interface that lets you control and grab info about the currently playing video

https://autohotkey.com/board/topic/8388 ... ia-player/

one idea is to check every two seconds if the current elapsed time of the currently playing video is the same aka video is frozen or not

Code: Select all

SetTimer, checkVlcIsPlaying, 2000
return

checkVlcIsPlaying:
this_time := VLCHTTP2_Time() 
if (this_time = last_time)
    VLCHTTP2_Close()
last_time := this_time
return

#include VLCHTTP2.ahk

Re: Need help with pixel detection reaction

Posted: 08 Mar 2018, 10:49
by flamingonion
Blackholyman wrote:also to what @BoBo said there is a VLC http interface that lets you control and grab info about the currently playing video

https://autohotkey.com/board/topic/8388 ... ia-player/

one idea is to check every two seconds if the current elapsed time of the currently playing video is the same aka video is frozen or not

Code: Select all

SetTimer, checkVlcIsPlaying, 2000
return

checkVlcIsPlaying:
this_time := VLCHTTP2_Time() 
if (this_time = last_time)
    VLCHTTP2_Close()
last_time := this_time
return

#include VLCHTTP2.ahk
Its not just my vlc but other applications of mine including office, games even chrome do get this kind of frozen. I think its Nvidia driver's issue since it occasionally stops working and restart, leaving a random active window frozen, sometimes its black screen, sometimes its kinda like all colors messing up. So I think a general pixel script is good enough for the situation I'm having :)

Re: Need help with pixel detection reaction

Posted: 08 Mar 2018, 20:13
by jeeswg
How about using SendMessage on the window and checking the reply. Or WinMove by 1 pixel and WinGetPos. Or WinGet Style and WinSet Style to the same style. Some kind of action that will give a different response based on whether the window has crashed or not.