Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The documentation for <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/ms648390.aspx" rel="nofollow noreferrer"><code>GetCursorPos</code></a> says:</p> <blockquote> <p>The input desktop must be the current desktop when you call GetCursorPos. Call OpenInputDesktop to determine whether the current desktop is the input desktop. If it is not, call SetThreadDesktop with the HDESK returned by OpenInputDesktop to switch to that desktop.</p> </blockquote> <p>You can fall foul of this, most commonly when unlocking a workstation. In my code I replace <code>GetCursorPos</code> with this variant:</p> <pre><code>function GetCursorPos(var lpPoint: TPoint): BOOL; stdcall; (* The GetCursorPos API in user32 fails if it is passed a memory address &gt;2GB which breaks LARGEADDRESSAWARE apps. We counter this by calling GetCursorInfo instead which does not suffer from the same problem. In addition we have had problems with GetCursorPos failing when called immediately after a password protected screensaver or a locked workstation re-authenticates. This problem initially appeared with XP SP1 and is brought about because TMouse.GetCursorPos checks the return value of the GetCursorPos API call and raises an OS exception if the API has failed. *) var CursorInfo: TCursorInfo; begin CursorInfo.cbSize := SizeOf(CursorInfo); Result := GetCursorInfo(CursorInfo); if Result then begin lpPoint := CursorInfo.ptScreenPos; end else begin lpPoint := Point(0, 0); end; end; </code></pre> <p>You can use your favourite code hooking mechanism to replace <code>GetCursorPos</code>. I do it like so:</p> <pre><code>RedirectProcedure(@Windows.GetCursorPos, @CodePatcher.GetCursorPos); </code></pre> <p>with <code>RedirectProcedure</code> as described here: <a href="https://stackoverflow.com/questions/8978177/patch-routine-call-in-delphi#answer-8978266">Patch routine call in delphi</a></p> <p>It turned out for my particular scenario, that <code>GetCursorPos</code> would fail, but <code>GetCursorInfo</code> would not fail. But as has been pointed out in the comments, there are scenarios where <code>GetCursorInfo</code> will also fail. In that case you might find it expedient to arrange that the patched function does not return <code>False</code>.</p> <p>As for <code>GetKeyState</code>, I'm not sure about that one. It's quite possibly similar but <code>GetKeyState</code> is an API that I am not personally familiar with.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload