poke into memory

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
User avatar
PepsiHog
Automation Wizard
Posts: 512
Joined: Wed Apr 08, 2009 4:19 pm
Location: Florida

poke into memory

Post by PepsiHog » Wed Nov 15, 2017 8:36 pm

Hello Everyone,

As I went to post this I realized it may not even be possible. But....

I have been using getpixelcolor> to... well do that. The color indicates a status (on/off). It is my vpn, green (the color I check for) is on. Like I said I use gpc to check if it is green and if not then my macro takes certain actions.

Question is: If you are not looking at the color, is it still there? More precisely, if the color is covered by another window is it still colored or is that an illusion?

What I'd like is to keep an eye on the color, regardless of windows that may cover the color.

Possible? With MS? How?

Thanks,
PepsiHog
Windows 7

PepsiHog. Yep! I drink LOTS of Pepsi (still..in 2024) AND enjoy programming. (That's my little piece of heaven!)

The immensity of the scope of possibilities within Macro Scheduler pushes the user beyond just macros!

User avatar
Marcus Tettmar
Site Admin
Posts: 7380
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Re: poke into memory

Post by Marcus Tettmar » Thu Nov 16, 2017 2:42 pm

No. GetPixelColor gets the color of the pixel on the screen. If a window shows green at that pixel and then you cover it up with something which is not green, then that pixel is not green any more. You don't see it, it isn't there, GetPixelColor will get whatever is now showing at that pixel.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

User avatar
JRL
Automation Wizard
Posts: 3501
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Re: poke into memory

Post by JRL » Thu Nov 16, 2017 3:07 pm

PH,

You should be able to use the BitBlt library function to grab the pixel then display it on a one pixel stayontop dialog that you could keep at your desktop's 0,0 position. You could then test the color on the one pixel sized dialog using getpixelcolor>.

Lunch is in a couple of hours, I'll see if I can make it work.

User avatar
JRL
Automation Wizard
Posts: 3501
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Re: poke into memory

Post by JRL » Thu Nov 16, 2017 9:09 pm

Here's an example. This should work as is with Windows 10 version of MSPaint.

Open MSPaint. The "File" button is blue so the color for the "vMyChosenColor" variable is that shade of blue. After opening paint start the following script. If all goes well the script will go into a loop and do nothing. Hover your mouse over the Paint "File" button and the color will change. That should cause a message to pop up on the screen. Clear the message and the script will end.

If that all worked, Then the example is ready to test. Start paint, run the script, cover up paint with windows so you cannot see the blue "File" button. The script should happily loop forever. But focus paint and hover the mouse over the button and the script will dispaly its message. when the message is dismissed the script will end.

Thus proving that what I think you asked for is possible. But not really straightforward.

Code: Select all

//Fill these variables to suit
Let>vWindowToMonitor=Paint
Let>vMyChosenColor=13269273
Let>vXpositionOfMonitoredPixel=5
Let>vYpositionOfMonitoredPixel=45


OnEvent>key_down,VK27,0,Quit

Dialog>Dialog1
object Dialog1: TForm
  BorderStyle = bsNone
  ClientHeight = 1
  ClientWidth = 1
  FormStyle = fsStayOnTop
end
EndDialog>Dialog1

Let>WIN_USEHANDLE=1
  MoveWindow>Dialog1.handle,0,0
Let>WIN_USEHANDLE=0

Show>Dialog1

GetWindowHandle>%vWindowToMonitor%*,WindowHandle

//Get the device contexts of the two windows
LibFunc>user32,GetDC,HDC1,Dialog1.handle
LibFunc>user32,GetDC,HDC3,WindowHandle
  
Label>Loop
  //For a dialog to stay on top while complied,  it has to keep "moving"
  Let>WIN_USEHANDLE=1
    MoveWindow>Dialog1.handle,0,0
  Let>WIN_USEHANDLE=0
  LibFunc>Gdi32,StretchBlt,SBres,HDC1,0,0,1,1,HDC3,vXpositionOfMonitoredPixel,vYpositionOfMonitoredPixel,1,1,13369376
  Wait>0.1
  //Get the color of the pixel and compare it to the desired color
  GetPixelColor>0,0,vColor
  If>vColor=vMyChosenColor
  Else
    MDL>Color %vMyChosenColor% is no longer visible in %vWindowToMonitor%
    GoSub>Quit
  EndIf
Goto>Loop

SRT>Quit
  // Need to release the device contexts or the eventually run out of space and stop working.
  LibFunc>user32,ReleaseDC,Dialog1.handle,HDC1_1,HDC1
  LibFunc>user32,ReleaseDC,WindowHandle,HDC3_1,HDC2
  Exit>0
END>Quit

User avatar
PepsiHog
Automation Wizard
Posts: 512
Joined: Wed Apr 08, 2009 4:19 pm
Location: Florida

Re: poke into memory

Post by PepsiHog » Mon Nov 20, 2017 2:29 pm

@Marcus
Yea, that is what I was thinking. The screen is made up of pixels and each change according to what is in that area. But I wasn't absolutely certain, so I asked. Thanks.

@JRL,
Thanks JRL. Nice piece of work. I like it and I am saving it for use. How much money should I send you in the mail? :wink: As for my project I came up with something else. The icon in the taskbar turns green when it is on and red when off. That is what I have my macro watching now. Works pretty good. Don't know why I didn't think of doing that originally.

Thanks,
PepsiHog
Windows 7

PepsiHog. Yep! I drink LOTS of Pepsi (still..in 2024) AND enjoy programming. (That's my little piece of heaven!)

The immensity of the scope of possibilities within Macro Scheduler pushes the user beyond just macros!

Post Reply
cron
Sign up to our newsletter for free automation tips, tricks & discounts