Monitoring a part of the screen

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
teadrinker
Posts: 4309
Joined: 29 Mar 2015, 09:41
Contact:

Re: Monitoring a part of the screen

06 Sep 2021, 10:14

Must be Thumb%i% := new ThumbnailGui(hThumb%i%, 600, 600, WinExist("A"), source%i%_X, source%i%_Y, source%i%_W, source%i%_H, true)
Fulminare
Posts: 369
Joined: 26 Jun 2021, 20:15

Re: Monitoring a part of the screen

06 Sep 2021, 10:22

Yes the video now occupies the entire gui

I made some mistake in entering the coordinates hence its not showing the video itself properly

but it is working
Fulminare
Posts: 369
Joined: 26 Jun 2021, 20:15

Re: Monitoring a part of the screen

07 Sep 2021, 00:00

Okay, a new complication

I have adjusted the coordinates, w&h e.t.c and its working well

Now I have this gui showing the video feed in place of the native zoom application's.

The Guis are positioned in a "top & bottom" layout.

Along with these guis, the zoom video feed is also displayed (naturally)

This is a distracting factor. To eliminate that, I made the following Gui that shows a black rectangle in the place of the zoom's video feed

Code: Select all

^b::
#SingleInstance, Force
Gui, Info:+ToolWindow -SysMenu -Caption ; +AlwaysOnTop
Gui, Info:Add, Progress, x0 y275 w1980 h535 BackgroundBlack ; Black
Gui, Info:Font, cFF0000 s12 , verdana ;red
Gui, Info:Color, CCCCCC
Gui, Info:Show, NoActivate x10 y-09, uptime ; screen position here
WinSet, TransColor, CCCCCC 255, uptime
Gui, Info:Show
Return
Esc::ExitApp
The problem is, on pressing "F1" the "Video feed monitoring" Gui is showing this black rectangle as it is comes in the way of the video shown in zoom.


if there a way to make the "Video feed monitoring" Gui show what's beneath the "black rectangle" gui ?
teadrinker
Posts: 4309
Joined: 29 Mar 2015, 09:41
Contact:

Re: Monitoring a part of the screen

07 Sep 2021, 08:03

The Gui shows exactly what is being rendered in the source window. I have no Zoom, but I tried Windows Media Player as the source window. If the Media Player window is overlapped with another, the Gui continues to display the video. If your Gui shows the black rectangle, it means, that Zoom stops rendering when overlapped.
Fulminare
Posts: 369
Joined: 26 Jun 2021, 20:15

Re: Monitoring a part of the screen

07 Sep 2021, 11:34

Is there no solution for this ?
Fulminare
Posts: 369
Joined: 26 Jun 2021, 20:15

Re: Monitoring a part of the screen

07 Sep 2021, 23:56

Just for updating you, these are my observations,


1. BLACK BAR GUI

running your script before the black bar gui script is not blocking the video feed shown in your gui.

i.e
run your script,
open zoom (that is already running and has both the participants)
press "F1"
- (the video from zoom is now shown in your gui)

next

run the black bar gui
open zoom
press the hotkey for the said gui ( which is ctrl b )
- (a black rectangle is shown in place of the zoom video)

but the video feed shown in your gui doesn't show the black rectangle.




2.

Returning to the desktop while the feed in your gui is on, freezes it.

That's not happening when chrome is opened

i.e the video feed in the gui runs as usual
teadrinker
Posts: 4309
Joined: 29 Mar 2015, 09:41
Contact:

Re: Monitoring a part of the screen

08 Sep 2021, 00:55

Fulminare wrote: but the video feed shown in your gui doesn't show the black rectangle.
When you press F1 the hWnd of the Zoom window must be passed as the fourth parameter here

Code: Select all

Thumb%i% := new ThumbnailGui(hThumb%i%, 400, 300, WinExist("A"), source%i%_X, source%i%_Y, source%i%_W, source%i%_H, true)
where WinExist("A") is placed now. You can replace WinExist("A") with WinExist("Title of the Zoom window here").
Fulminare wrote: Returning to the desktop while the feed in your gui is on, freezes it
I don't quite understand, what you mean by «Returning to the desktop». Anyway, I've not encountered such behavior.
Fulminare
Posts: 369
Joined: 26 Jun 2021, 20:15

Re: Monitoring a part of the screen

08 Sep 2021, 03:25

I didn't understand this
When you press F1 the hWnd of the Zoom window must be passed as the fourth parameter here


What I meant was, on opening the desktop ( Windows + D ) the gui video feed gets frozen
I don't quite understand, what you mean by «Returning to the desktop». Anyway, I've not encountered such behavior.


But that doesn't happen when chrome is opened


Gui video feed on - open desktop - gui video feed freezes


Gui video feed on - open chrome - gui video feed is normal
Fulminare
Posts: 369
Joined: 26 Jun 2021, 20:15

Re: Monitoring a part of the screen

08 Sep 2021, 05:04

Also, I tried pasting this code into a main script that I have.

My script basically opens zoom , copies the link , sends it to a contact in Whatsapp and return to zoom



on returning to zoom, the two blank guis were shown, but pressing F1 didn't display the feed from zoom into the gui.

Instead it showed the following error message

" Error: DwmRegisterThumbnail failed
teadrinker
Posts: 4309
Joined: 29 Mar 2015, 09:41
Contact:

Re: Monitoring a part of the screen

08 Sep 2021, 13:20

Fulminare wrote: I didn't understand this
You can find out what you need here: WinExist()
Fulminare wrote: What I meant was, on opening the desktop ( Windows + D ) the gui video feed gets frozen
Video freezes not because you open the desktop, but because the Zoom window gets minimized, and stops rendering.
Fulminare wrote: Also, I tried pasting this code into a main script that I have.
What exactly did you paste?
Fulminare
Posts: 369
Joined: 26 Jun 2021, 20:15

Re: Monitoring a part of the screen

08 Sep 2021, 19:57

I will read about that
Last edited by Fulminare on 08 Sep 2021, 20:09, edited 2 times in total.
Fulminare
Posts: 369
Joined: 26 Jun 2021, 20:15

Re: Monitoring a part of the screen

08 Sep 2021, 20:00

So the zoom window doesn't get minimised when chrome or other apps are opened ?


I pasted your code

using - #include somehow didn't work
teadrinker
Posts: 4309
Joined: 29 Mar 2015, 09:41
Contact:

Re: Monitoring a part of the screen

08 Sep 2021, 20:05

Fulminare wrote: So the zoom window doesn't get minimised when chrome or other apps are opened ?
I don't know what exactly happens.
Fulminare wrote: I pasted your code
Show your code again, as it is now.
Fulminare
Posts: 369
Joined: 26 Jun 2021, 20:15

Re: Monitoring a part of the screen

08 Sep 2021, 21:10

Code: Select all

#SingleInstance

Send ^#6

Sleep 100



Gui, New, hwndhThumb1 -DpiScale +AlwaysOnTop +Owner, First Area
Gui, Show, x451 y0 w950 h530
Gui, New, hwndhThumb2 -DpiScale +AlwaysOnTop +Owner, Second Area
Gui, Show, x451 y520 w950 h530
source1_X := 139, source1_Y := 280, source1_W := 710, source1_H := 525   ; first area in the source window
source2_X := 971, source2_Y := 275, source2_W := 945, source2_H := 530 ; second area in the source window
;Sleep 1000

Send {F1}

Return

F1::
   Loop 2 {
      i := A_Index
      Thumb%i% := new ThumbnailGui(hThumb%i%, 950, 530, WinExist("Zoom Meeting"), source%i%_X, source%i%_Y, source%i%_W, source%i%_H, true)
   }
   Return

class ThumbnailGui
{
   __New(hWndThumb, thumbW, thumbH, hWndSource, sourceX, sourceY, sourceW, sourceH, clientOnly := false) {
      this.hLib := DllCall("LoadLibrary", "Str", "dwmapi.dll")
      if DllCall("dwmapi\DwmRegisterThumbnail", "Ptr", hWndThumb, "Ptr", hWndSource, "PtrP", hThumbnailId) != 0
         throw "DwmRegisterThumbnail failed"
      this.ThumbnailId := hThumbnailId
      this.SetSourceRegion(sourceX, sourceY, sourceW, sourceH, clientOnly)
      this.SetThumbRegion(thumbW, thumbH)
   }
   __Delete() {
      DllCall("dwmapi\DwmUnregisterThumbnail", "Ptr", this.ThumbnailId)
      DllCall("FreeLibrary", "Ptr", this.hLib)
   }
   SetSourceRegion(X, Y, W, H, clientOnly) {
      this.SetRegion(DWM_TNP_RECTSOURCE := 0x2, X, Y, W, H, clientOnly)
   }
   SetThumbRegion(W, H) {
      this.SetRegion(DWM_TNP_RECTDESTINATION := 0x1, 0, 0, W, H)
   }
   SetRegion(flag, X, Y, W, H, clientOnly := false) {
      static DWM_TNP_SOURCECLIENTAREAONLY := 0x10
           , DWM_TNP_RECTDESTINATION := 0x1
           , DWM_TNP_RECTSOURCE := 0x2
      VarSetCapacity(DWM_THUMBNAIL_PROPERTIES, 48, 0)
      flags := flag | DWM_TNP_SOURCECLIENTAREAONLY*(flag = DWM_TNP_RECTSOURCE)
      NumPut( flags     , DWM_THUMBNAIL_PROPERTIES)
      NumPut( X         , DWM_THUMBNAIL_PROPERTIES,  4 + 16*(flag = DWM_TNP_RECTSOURCE) )
      NumPut( Y         , DWM_THUMBNAIL_PROPERTIES,  8 + 16*(flag = DWM_TNP_RECTSOURCE) )
      NumPut( W + X     , DWM_THUMBNAIL_PROPERTIES, 12 + 16*(flag = DWM_TNP_RECTSOURCE) )
      NumPut( H + Y     , DWM_THUMBNAIL_PROPERTIES, 16 + 16*(flag = DWM_TNP_RECTSOURCE) )
      NumPut( clientOnly, DWM_THUMBNAIL_PROPERTIES, 44, "UInt")
      this.UpdateThumbnailProperties(&DWM_THUMBNAIL_PROPERTIES)
   }
   UpdateThumbnailProperties(pProp) {
      DllCall("dwmapi\DwmUpdateThumbnailProperties", "Ptr", this.ThumbnailId, "Ptr", pProp)
   }
}


It's working now

Instead of placing "send {F1}" before the first return, I placed it at the end of the script.





I don't know what exactly happens.
Zoom is getting minimised when desktop is opened, but that's not happening when I open any other application such as chrome, OBS, Whatsapp e.t.c

hence, the gui video feed freezes on opening the desktop.
Fulminare
Posts: 369
Joined: 26 Jun 2021, 20:15

Re: Monitoring a part of the screen

16 Sep 2021, 07:11

@teadrinker

There is something strange happening with your code

see

Code: Select all

Gui, New, hwndhThumb1 -DpiScale +AlwaysOnTop +Owner, First Area
Gui, Show, x451 y0 w950 h530
Gui, New, hwndhThumb2 -DpiScale +AlwaysOnTop +Owner, Second Area
Gui, Show, x451 y520 w950 h530
source1_X := 139, source1_Y := 280, source1_W := 710, source1_H := 525   ; first area in the source window
source2_X := 971, source2_Y := 275, source2_W := 945, source2_H := 530 ; second area in the source window
Sleep 100

Send, {F1}

Return

F1::
   Loop 2 {
      i := A_Index
      Thumb%i% := new ThumbnailGui(hThumb%i%, 950, 530, WinExist("A"), source%i%_X, source%i%_Y, source%i%_W, source%i%_H, true)
   }
   Return

class ThumbnailGui
{
   __New(hWndThumb, thumbW, thumbH, hWndSource, sourceX, sourceY, sourceW, sourceH, clientOnly := false) {
      this.hLib := DllCall("LoadLibrary", "Str", "dwmapi.dll")
      if DllCall("dwmapi\DwmRegisterThumbnail", "Ptr", hWndThumb, "Ptr", hWndSource, "PtrP", hThumbnailId) != 0
         throw "DwmRegisterThumbnail failed"
      this.ThumbnailId := hThumbnailId
      this.SetSourceRegion(sourceX, sourceY, sourceW, sourceH, clientOnly)
      this.SetThumbRegion(thumbW, thumbH)
   }
   __Delete() {
      DllCall("dwmapi\DwmUnregisterThumbnail", "Ptr", this.ThumbnailId)
      DllCall("FreeLibrary", "Ptr", this.hLib)
   }
   SetSourceRegion(X, Y, W, H, clientOnly) {
      this.SetRegion(DWM_TNP_RECTSOURCE := 0x2, X, Y, W, H, clientOnly)
   }
   SetThumbRegion(W, H) {
      this.SetRegion(DWM_TNP_RECTDESTINATION := 0x1, 0, 0, W, H)
   }
   SetRegion(flag, X, Y, W, H, clientOnly := false) {
      static DWM_TNP_SOURCECLIENTAREAONLY := 0x10
           , DWM_TNP_RECTDESTINATION := 0x1
           , DWM_TNP_RECTSOURCE := 0x2
      VarSetCapacity(DWM_THUMBNAIL_PROPERTIES, 48, 0)
      flags := flag | DWM_TNP_SOURCECLIENTAREAONLY*(flag = DWM_TNP_RECTSOURCE)
      NumPut( flags     , DWM_THUMBNAIL_PROPERTIES)
      NumPut( X         , DWM_THUMBNAIL_PROPERTIES,  4 + 16*(flag = DWM_TNP_RECTSOURCE) )
      NumPut( Y         , DWM_THUMBNAIL_PROPERTIES,  8 + 16*(flag = DWM_TNP_RECTSOURCE) )
      NumPut( W + X     , DWM_THUMBNAIL_PROPERTIES, 12 + 16*(flag = DWM_TNP_RECTSOURCE) )
      NumPut( H + Y     , DWM_THUMBNAIL_PROPERTIES, 16 + 16*(flag = DWM_TNP_RECTSOURCE) )
      NumPut( clientOnly, DWM_THUMBNAIL_PROPERTIES, 44, "UInt")
      this.UpdateThumbnailProperties(&DWM_THUMBNAIL_PROPERTIES)
   }
   UpdateThumbnailProperties(pProp) {
      DllCall("dwmapi\DwmUpdateThumbnailProperties", "Ptr", this.ThumbnailId, "Ptr", pProp)
   }
}

When I run that It acknowledges the " Send {F1} ( I have added that in line 9 )command and automatically pulls the display feed from zoom ( for the purpose of testing I have changed WinExist("Zoom Meeting") to WinExist("A") )



But when I include that in the following function, only the two blank guis are shown. Of course, on pressing F1 the zoom feed gets shown in the guis. but it is not acknowledging the Send {F1} command when included in the function

Code: Select all

^!v::
x:= 272 ;x coordinate of pixel to check.
y:= 83 ;y coordinate of pixel to check.
targetcolor:= 0x1A1A1A ;color to be matched in hexadecimal blue-green-red (BGR) format.

Loop
{
    PixelGetColor, currentcolor, x, y
    if (currentcolor=targetcolor)
    {
        #Include C:\Users\user\Desktop\New AutoHotkey Script (4).ahk
		
    }
    else
    {
        ;do something
    }
}

Can you please help by telling why does this happen ?
User avatar
boiler
Posts: 16767
Joined: 21 Dec 2014, 02:44

Re: Monitoring a part of the screen

16 Sep 2021, 08:25

It doesn’t make sense to #Include the first script in the place you’ve shown in the second script. You have Return lines and hotkey definitions that will cause the loop to stop executing because the auto-execute section ends. If that’s what you did, then the resulting script looks like this:

Code: Select all

^!v::
x:= 272 ;x coordinate of pixel to check.
y:= 83 ;y coordinate of pixel to check.
targetcolor:= 0x1A1A1A ;color to be matched in hexadecimal blue-green-red (BGR) format.

Loop
{
    PixelGetColor, currentcolor, x, y
    if (currentcolor=targetcolor)
    {
Gui, New, hwndhThumb1 -DpiScale +AlwaysOnTop +Owner, First Area
Gui, Show, x451 y0 w950 h530
Gui, New, hwndhThumb2 -DpiScale +AlwaysOnTop +Owner, Second Area
Gui, Show, x451 y520 w950 h530
source1_X := 139, source1_Y := 280, source1_W := 710, source1_H := 525   ; first area in the source window
source2_X := 971, source2_Y := 275, source2_W := 945, source2_H := 530 ; second area in the source window
Sleep 100

Send, {F1}

Return

F1::
   Loop 2 {
      i := A_Index
      Thumb%i% := new ThumbnailGui(hThumb%i%, 950, 530, WinExist("A"), source%i%_X, source%i%_Y, source%i%_W, source%i%_H, true)
   }
   Return

class ThumbnailGui
{
   __New(hWndThumb, thumbW, thumbH, hWndSource, sourceX, sourceY, sourceW, sourceH, clientOnly := false) {
      this.hLib := DllCall("LoadLibrary", "Str", "dwmapi.dll")
      if DllCall("dwmapi\DwmRegisterThumbnail", "Ptr", hWndThumb, "Ptr", hWndSource, "PtrP", hThumbnailId) != 0
         throw "DwmRegisterThumbnail failed"
      this.ThumbnailId := hThumbnailId
      this.SetSourceRegion(sourceX, sourceY, sourceW, sourceH, clientOnly)
      this.SetThumbRegion(thumbW, thumbH)
   }
   __Delete() {
      DllCall("dwmapi\DwmUnregisterThumbnail", "Ptr", this.ThumbnailId)
      DllCall("FreeLibrary", "Ptr", this.hLib)
   }
   SetSourceRegion(X, Y, W, H, clientOnly) {
      this.SetRegion(DWM_TNP_RECTSOURCE := 0x2, X, Y, W, H, clientOnly)
   }
   SetThumbRegion(W, H) {
      this.SetRegion(DWM_TNP_RECTDESTINATION := 0x1, 0, 0, W, H)
   }
   SetRegion(flag, X, Y, W, H, clientOnly := false) {
      static DWM_TNP_SOURCECLIENTAREAONLY := 0x10
           , DWM_TNP_RECTDESTINATION := 0x1
           , DWM_TNP_RECTSOURCE := 0x2
      VarSetCapacity(DWM_THUMBNAIL_PROPERTIES, 48, 0)
      flags := flag | DWM_TNP_SOURCECLIENTAREAONLY*(flag = DWM_TNP_RECTSOURCE)
      NumPut( flags     , DWM_THUMBNAIL_PROPERTIES)
      NumPut( X         , DWM_THUMBNAIL_PROPERTIES,  4 + 16*(flag = DWM_TNP_RECTSOURCE) )
      NumPut( Y         , DWM_THUMBNAIL_PROPERTIES,  8 + 16*(flag = DWM_TNP_RECTSOURCE) )
      NumPut( W + X     , DWM_THUMBNAIL_PROPERTIES, 12 + 16*(flag = DWM_TNP_RECTSOURCE) )
      NumPut( H + Y     , DWM_THUMBNAIL_PROPERTIES, 16 + 16*(flag = DWM_TNP_RECTSOURCE) )
      NumPut( clientOnly, DWM_THUMBNAIL_PROPERTIES, 44, "UInt")
      this.UpdateThumbnailProperties(&DWM_THUMBNAIL_PROPERTIES)
   }
   UpdateThumbnailProperties(pProp) {
      DllCall("dwmapi\DwmUpdateThumbnailProperties", "Ptr", this.ThumbnailId, "Ptr", pProp)
   }
}
	
    }
    else
    {
        ;do something
    }
}

When you review the above combined script, does it make sense to you?
Fulminare
Posts: 369
Joined: 26 Jun 2021, 20:15

Re: Monitoring a part of the screen

16 Sep 2021, 08:43

When you review the above combined script, does it make sense to you?
well, like , I thought as the first script works as intended individually, (i.e it takes into account the send {f1} command) and gives the output.)

placing it in the "pixel trigger" script would make it work when a pixel changes colour.

regarding the return and the hotkey,

this first script is working (individually that is,) even when I blocked the "F1:: and "return" lines

Code: Select all

Send, {F1}

;Return

;F1::

But the loop is needed for monitoring change in pixel colour.
What should I do ?

Is there a way to search for pixel colour change with out the loop ?
User avatar
boiler
Posts: 16767
Joined: 21 Dec 2014, 02:44

Re: Monitoring a part of the screen

16 Sep 2021, 08:54

Having a loop isn't the problem. Plopping a full script that includes a fully realized auto-execute section and hotkey definitions in the middle of what is meant to be the flow of code in another script is the problem. Look at what you have as an entire script and pay attention to how the code flows and the placement of commands that are meant to be executed in that flow vs. code that is meant to be triggered when a hotkey is pressed. Try to produce a script that makes sense from that perspective, then post it when you get stuck.
Fulminare
Posts: 369
Joined: 26 Jun 2021, 20:15

Re: Monitoring a part of the screen

16 Sep 2021, 09:01

Okay I will do that

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: No registered users and 134 guests