Jump to content

Recommended Posts

Posted (edited)

Wondering how to detect the pen's cursor location in the situations where MouseGetPos() doesn't work.

I'm using a Surface Pro 4 and have noticed that MouseGetPos() doesn't always update coordinates when using the pen instead of the mouse to control the cursor (but does on some windows).
I read somewhere that the pen is not treated exactly the same as a mouse, so am not surprised by this behaviour.

 

An script to demonstrate this behaviour with the SciTE4AutoIt3 editor and EDGE (or CHROME) running side by side:

 

#include <GUIConstants.au3>

HotKeySet("{ESC}", "Terminate")

Global $mousex,$mousey
Global $oldx = MouseGetPos(0)
Global $oldy = MouseGetPos(1)

Global $Form1 = GUICreate("Mouse Pos - ESC to exit", 197, 33, 400, 408, -1, BitOR($WS_EX_TOOLWINDOW,$WS_EX_TOPMOST))
Global $Label1 = GUICtrlCreateLabel("0,0", 0, 8, 196, 17, $SS_CENTER)
GUISetState(@SW_SHOW)


While 1

    $mousex = MouseGetPos(0)
    $mousey = MouseGetPos(1)
    if $mousex<>$oldx or $mousey<>$oldy then
        $oldx=$mousex
        $oldy=$mousey
        GUICtrlSetData($label1, "")
        GUICtrlSetData($Label1, $mousex & ", " & $mousey)
    endif
     sleep(100)
WEnd


Func Terminate()
    Exit
EndFunc

Move the cursor using the mouse between windows and coordinates keep updating (Expected behaviour)
Move the cursor using the pen between widows - cursor coordinates doesn't update when over the EDGE/CHROME window, but do when over SciTE4AutoIt3.

This also happens with CHROME as well as both WORD and ONENOTE's document windows (updates on the toolbars etc, but not over the "page") … 

Edited by twothirtyone
typo
Posted (edited)

My video tutorials : ( In construction )  || My Discord : https://discord.gg/S9AnwHw

How to Ask Help ||  UIAutomation From Junkew || WebDriver From Danp2 || And Water's UDFs in the Quote

Spoiler

 Water's UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Posted

Now have a dll call - but still using mouse (using GetCursorPos)

From: https://docs.microsoft.com/en-us/windows/desktop/api/winuser/,  I think I need GetPointerInfo.

Something like:  DllCall("User32.dll","int","GetPointerInfo "int", $pointerId,"ptr",DllStructGetPtr($pointerinfo))

But api docs state:

BOOL GetPointerInfo(
  UINT32       pointerId,
  POINTER_INFO *pointerInfo
)
;

and, to get pointerId

void GET_POINTERID_WPARAM(

   wParam
)
;

I'm not sure how to get pointerId / pointerInfo …

 

Any help will be greatly appreciated … will keep looking/reading though …

 

#include <GUIConstants.au3>

HotKeySet("{ESC}", "Terminate")

Global $pen_x,$pen_y
Global $oldx = 0
Global $oldy = 0
Global $xy=DllStructCreate("long x;long y")

Global $Form1 = GUICreate("Pen Pos - ESC to exit", 197, 33, 400, 408, -1, BitOR($WS_EX_TOOLWINDOW,$WS_EX_TOPMOST))
Global $Label1 = GUICtrlCreateLabel("0,0", 0, 8, 196, 17, $SS_CENTER)
GUISetState(@SW_SHOW)


While 1
    $aDllCallReturn = DllCall("User32.dll","int","GetCursorPos","ptr",DllStructGetPtr($xy))
        If @error Then
            Switch @error

                Case 1
                    ConsoleWrite("DllCall error (User32.dll/GetCursorPos): Unable to use the DLL file.  Possibly a problem with the parameters." & @CRLF)
                Case 2
                    ConsoleWrite("DllCall error (User32.dll/GetCursorPos): Unknown return type." & @CRLF)
                Case 3
                    ConsoleWrite("DllCall error (User32.dll/GetCursorPos): Function not found in DLL file.  Remember that function names are case sensitive." & @CRLF)
                Case 4
                    ConsoleWrite("DllCall error (User32.dll/GetCursorPos): Incorrect number of parameters." & @CRLF)
                Case 5
                    ConsoleWrite("DllCall error (User32.dll/GetCursorPos): Bad parameter." & @CRLF)
                Case Else
                    ConsoleWrite("DllCall error (User32.dll/GetCursorPos): Unknown/unspecified error." & @CRLF)
            EndSwitch
            Exit
        EndIf


    $pen_x = DllStructGetData($xy,"x") ;MouseGetPos(0)
    $pen_y = DllStructGetData($xy,"y") ;MouseGetPos(1)
    if $pen_x<>$oldx or $pen_y<>$oldy then
        $oldx=$pen_x
        $oldy=$pen_y
        GUICtrlSetData($label1, "")
        GUICtrlSetData($Label1, "x: "&$pen_x&" y:"&$pen_y)
    endif
     sleep(100)
WEnd


Func Terminate()
    Exit
EndFunc

 

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...