Need help with pixel detection reaction

Get help with using AutoHotkey and its commands and hotkeys
flamingonion
Posts: 4
Joined: 11 Feb 2018, 21:54

Need help with pixel detection reaction

Post by flamingonion » 07 Mar 2018, 00:58

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!
User avatar
Blackholyman
Posts: 1271
Joined: 29 Sep 2013, 22:57
Facebook: socialjsz
Google: +Jszapp
Location: Denmark
Contact:

Re: Need help with pixel detection reaction

Post by Blackholyman » 07 Mar 2018, 03:07

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...
Also check out:
[hr][/hr]The Monthly AutoHotkey Webinars

My Autohotkey Blog
:dance: [hr][/hr]
flamingonion
Posts: 4
Joined: 11 Feb 2018, 21:54

Re: Need help with pixel detection reaction

Post by flamingonion » 07 Mar 2018, 11:32

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!
BoBo
Posts: 2515
Joined: 13 May 2014, 17:15

Re: Need help with pixel detection reaction

Post by BoBo » 07 Mar 2018, 11:53

@flamingonion
what is your final target? To close vlc in a more reliable way once a video recording has finished?
flamingonion
Posts: 4
Joined: 11 Feb 2018, 21:54

Re: Need help with pixel detection reaction

Post by flamingonion » 07 Mar 2018, 19:26

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.
BoBo
Posts: 2515
Joined: 13 May 2014, 17:15

Re: Need help with pixel detection reaction

Post by BoBo » 07 Mar 2018, 21:42

[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]
User avatar
Blackholyman
Posts: 1271
Joined: 29 Sep 2013, 22:57
Facebook: socialjsz
Google: +Jszapp
Location: Denmark
Contact:

Re: Need help with pixel detection reaction

Post by Blackholyman » 08 Mar 2018, 02:34

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
Also check out:
[hr][/hr]The Monthly AutoHotkey Webinars

My Autohotkey Blog
:dance: [hr][/hr]
flamingonion
Posts: 4
Joined: 11 Feb 2018, 21:54

Re: Need help with pixel detection reaction

Post by flamingonion » 08 Mar 2018, 10:49

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 :)
User avatar
jeeswg
Posts: 5136
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Need help with pixel detection reaction

Post by jeeswg » 08 Mar 2018, 20:13

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.
Post Reply

Return to “Ask For Help”