photonbuddy Posted November 29 Posted November 29 Hi All, I am writing a script to control the Reolink desktop client. My development machine is running Windows 10, while the target machine, our HTPC, is running Windows 11. I have just updated to the current release v3.3.18.0. The script works wonderfully on my development machine, but failed right from the first try on the HTPC. I then realised the colors were slightly different, so got the correct color codes from Au3Info, but I am still failing. [After writing a lengthy post, I realised there was 1 other difference between the 2 machines] I think I have found the problem. PixelGetColor uses different code than whatever Au3Info uses to get pixel color. PixelGetColor fails when running at a non-100% scaling. The attached image is a screenshot of the issue. The code to make the mouse box is: Func DoMouse() $mouse = MouseGetPos() $mgui = GUICreate("MouseTester", 200, 90, -1, 200, 0x80000000 + 0x00400000, 0x00000080 + 0x00000008) $MLoc = GUICtrlCreateLabel("Mouse Pos: x = " & $mouse[0] & ", y = " & $mouse[1], 10, 5, 180) $Pix = GUICtrlCreateLabel("Pixel Colour: " & Hex(PixelGetColor($mouse[0], $mouse[1])), 10, 25, 180) $WDim = GUICtrlCreateLabel("Window Size: " & $RLWinSize[2] & "x" & $RLWinSize[3], 10, 45, 180) GUICtrlCreateLabel("Numpad4 to exit", 10, 65, 180) GUISetState(@SW_SHOW) GUISetState(@SW_DISABLE) While 1 $mouse = MouseGetPos() Sleep(100) Select Case _IsPressed("67") ; = "{numpad7}" ;MsgBox(0, "", $nmsg) MouseMove($mouse[0] - 1, $mouse[1]) Case _IsPressed("69") ; = "{numpad9}" MouseMove($mouse[0] + 1, $mouse[1]) Case _IsPressed("68") ; = "{numpad8}" MouseMove($mouse[0], $mouse[1] - 1) Case _IsPressed("65") ; = "{numpad5}" MouseMove($mouse[0], $mouse[1] + 1) Case _IsPressed("64") ; = numpad4 ExitLoop EndSelect GUICtrlSetData($MLoc, "Mouse Pos: x = " & $mouse[0] & ", y = " & $mouse[1]) GUICtrlSetData($Pix, "Pixel Colour: " & PixelGetColor($mouse[0], $mouse[1])) WEnd GUIDelete($mgui) EndFunc ;==>DoMouse My perfectly running script on the development machine broke immediately when changing scale. AU3Info continued to return the correct colors. What do I replace PixelGetColor with so my code returns the same value as Au3Info?
ioa747 Posted November 29 Posted November 29 put at the top of your script DllCall("User32.dll", "bool", "SetProcessDpiAwarenessContext" , "HWND", "DPI_AWARENESS_CONTEXT" -2) and try I know that I know nothing
photonbuddy Posted November 29 Author Posted November 29 Thanks for the reply. That fixed the pixel color, which is great, but ... Now the mouse coordinates and screen size are being reported wrong. It reports the screen size as if no scaling has occurred. The mouse functions report positions as if no scaling is in effect. Au3Info still reports everything correctly.
ioa747 Posted November 29 Posted November 29 also tried with DllCall("User32.dll", "bool", "SetProcessDpiAwarenessContext" , "HWND", "DPI_AWARENESS_CONTEXT" -4) I know that I know nothing
argumentum Posted November 29 Posted November 29 Take a look at Control Viewer (mod.). That seem to be using "-3". 7 hours ago, photonbuddy said: It reports the screen size as if no scaling has occurred If it reports the physical size, then you're good. Just use the scaling as a factor to multiply/divide by, to get to the point in the monitor you want to get to. Maybe these help: _WinAPI_SetProcessDpiAwareness() screen scale script example "GuiCtrls_HiDpi" (UDF in progress) Example/UDF Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting.
Nine Posted November 29 Posted November 29 (edited) Tested on a 125% scale and working correctly : #include <WinAPI.au3> HotKeySet("{ESC}", Terminate) Local $nColor, $nScale = DllCall("Shcore.dll", "int", "GetScaleFactorForDevice", "int", 0)[0] / 100 ConsoleWrite("Scale = " & $nScale & @CRLF) While Sleep(200) $nColor = PixelGetColor(Int(MouseGetPos(0) * $nScale), Int(MouseGetPos(1) * $nScale)) ConsoleWrite(MouseGetPos(0) & "/" & MouseGetPos(1) & "/" & Hex($nColor) & @CRLF) WEnd Func Terminate() Exit EndFunc ps...I'm using it for my own purpose. Works well with my Screen Scraping UDF. So you now have a good solution... Edited November 29 by Nine better code “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Debug Messages Monitor UDF Screen Scraping Round Corner GUI UDF Multi-Threading Made Easy Interface Object based on Tag
photonbuddy Posted November 30 Author Posted November 30 (edited) 7 hours ago, Nine said: Tested on a 125% scale and working correctly : ps...I'm using it for my own purpose. Works well with my Screen Scraping UDF. So you now have a good solution... It doesn't work on my system, unless I am doing it wrong ... Turns out, I was 😒 I had bits of code from testing that was messing things up. Cleaned it all up, and now things seem to be working fine. My DoMouse() call now returns the correct window size and mouse coordinates, and the PixelGetColor also returns the right color. Thanks muchly for the help. Edited November 30 by photonbuddy Discovered I had left code laying around ...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now