DesktopMouseY() issue

Just starting out? Need help? Post your questions and find answers here.
BarryG
Addict
Addict
Posts: 3292
Joined: Thu Apr 18, 2019 8:17 am

DesktopMouseY() issue

Post by BarryG »

Hi, are there any known bugs with DesktopMouseX() or DesktopMouseY() at all? Because I'm using the following standalone code to test when the user has clicked the bottom of the desktop, but sometimes the Debug message appears when the left mouse button is clicked but the mouse is NOT at the bottom at all (the click was at the top, like clicking a link in a web page). So... what the?

Code: Select all

bottom_of_desktop=GetSystemMetrics_(#SM_CYSCREEN)-1
Repeat
  Delay(1)
  If GetAsyncKeyState_(#VK_LBUTTON) & $8000 And DesktopMouseY()=bottom_of_desktop
    Debug "Mouse clicked at bottom"
    Repeat : Delay(1) : Until GetAsyncKeyState_(#VK_LBUTTON)=0
  EndIf
ForEver
breeze4me
Enthusiast
Enthusiast
Posts: 511
Joined: Thu Mar 09, 2006 9:24 am
Location: S. Kor

Re: DesktopMouseY() issue

Post by breeze4me »

One possibility is the use of multiple monitors.
The GetSystemMetrics function returns only the value of the main monitor, so the coordinates on the other monitor may be different.
Therefore, get the resolution of the monitor where the mouse cursor is located and try it again.

Code: Select all

Define mi.MONITORINFO, pt.q
mi\cbSize = SizeOf(MONITORINFO)

bottom_of_desktop = -60000

Repeat
  GetCursorPos_(@pt)
  hMon = MonitorFromPoint_(pt, 0)
  If hMon
    If GetMonitorInfo_(hMon, mi)
      bottom_of_desktop = mi\rcMonitor\bottom - 1
    EndIf
  EndIf
  
  Delay(10)
  
  If GetAsyncKeyState_(#VK_LBUTTON) & $8000 And DesktopMouseY()=bottom_of_desktop
    Debug "Mouse clicked at bottom"
    Repeat : Delay(1) : Until GetAsyncKeyState_(#VK_LBUTTON)=0
  EndIf
ForEver
Or, if the results are different on the same monitor, it may be due to the program's delayed response, although rare.
BarryG
Addict
Addict
Posts: 3292
Joined: Thu Apr 18, 2019 8:17 am

Re: DesktopMouseY() issue

Post by BarryG »

Just a single monitor. And sometimes I never click the bottom of the desktop at all when testing my posted code, which can be for over an hour while just web-browsing like this. And then the debug message will pop up out of nowhere. Very weird. So if it's a delayed response, it's an extremely long one.

I noticed it happened once when I finished a long file copy and I clicked the target folder window to bring it to the front, but haven't been able to replicate that.
breeze4me
Enthusiast
Enthusiast
Posts: 511
Joined: Thu Mar 09, 2006 9:24 am
Location: S. Kor

Re: DesktopMouseY() issue

Post by breeze4me »

The DesktopMouseY function is only a wrapper function of the GetCursorPos API, so if there is a problem, it will be an OS level problem.

Code: Select all

longlong FUN_14000250c(void)
{
  tagPOINT local_res8 [4];
  
  GetCursorPos(local_res8);
  return (longlong)local_res8[0].y;
}
Just in case, the next time you test, restart the compiler first and try it.
BarryG
Addict
Addict
Posts: 3292
Joined: Thu Apr 18, 2019 8:17 am

Re: DesktopMouseY() issue

Post by BarryG »

It's hard to isolate because it happens very randomly. Oh well, I'll just keep watching and see if I can detect a pattern/reason.
Post Reply