Nothing so complicated, tzuk.
It's like mouse deltas are not discrete anymore. It has a delta but the bug made it seem cumulative (whether in the negative or positive direction).
Code: Select all
/*
"MouseLock" adapted from Torque3D source
x86 & x64 compatible AutoHotkey_L script
AutoHotkey_L => http://l.autohotkey.net/
Save as "MouseLock.ahk" & drop onto exe.
*/
Gui,1:-AlwaysOnTop +Caption +OwnDialogs +Resize
Gui,1:+LastFound
Global Gui1:=WinExist()
Gui,1:Margin,0,0
Global Gui1_Edit1_hWnd
Gui,1:Add,Edit,R35 W240 HwndGui1_Edit1_hWnd VGui1_Edit1
Gui,1:Show,W640 H480
OnMessage(0x0200,"WM_MOUSEMOVE")
return
~Esc::ExitApp
GuiClose:
GuiEscape:
ExitApp
WM_MOUSEMOVE(wParam,lParam)
{
; AutoHotkey drops messages without this line.
; Unfortunately it makes other messages dodgy.
; Actually, it'll deteriorate after some time.
Critical,-1
Edit:=""
VarSetCapacity(POINT,8)
NumPut(cursorX:=lParam&0xFFFF,POINT,0,"Int")
NumPut(cursorY:=lParam>>16,POINT,4,"Int")
; subsequent coordinates unaffected by sibling windows
DllCall("SetCapture","UPtr",Gui1,"UPtr")
VarSetCapacity(RECT,16)
DllCall("GetClientRect","UPtr",Gui1,"UPtr",&RECT,"Int")
DllCall("ClientToScreen","UPtr",Gui1,"UPtr",&RECT,"Int")
DllCall("ClientToScreen","UPtr",Gui1,"UPtr",&RECT+8,"Int")
RECT_left:=NumGet(RECT,0,"Int"),RECT_top:=NumGet(RECT,4,"Int")
RECT_right:=NumGet(RECT,8,"Int"),RECT_bottom:=NumGet(RECT,12,"Int")
DllCall("ClipCursor","UPtr",&RECT,"Int")
;// Convert the incoming client pos into a screen pos, so we can
;// accurately convert to relative coordinates.
DllCall("ClientToScreen","UPtr",Gui1,"UPtr",&POINT,"Int")
mouseX:=NumGet(POINT,0,"Int"),mouseY:=NumGet(POINT,4,"Int")
;// Hide the cursor before it's moved
; DllCall("ShowCursor","Int",FALSE,"Int")
;// Recenter the mouse if necessary (don't flood the message pump)
centerX:=(RECT_right+RECT_left)//2,centerY:=(RECT_bottom+RECT_top)//2
if(mouseX!=centerX||mouseY!=centerY)
{
DllCall("SetLastError","UInt",0)
BOOL:=DllCall("SetCursorPos","Int",centerX,"Int",centerY,"Int")
Edit.="SetCursorPos() returned " BOOL "`r`n" "GetLastError() returned " A_LastError "`r`n" """" FormatMessage(A_LastError) """" "`r`n"
}
;// Now we can calculate the position relative to the center we set.
deltaX:=mouseX-centerX
deltaY:=mouseY-centerY
;do_something_useful_with(deltaX,deltaY)
Text=mouseX=%mouseX% mouseY=%mouseY%`r`ncenterX=%centerX% centerY=%centerY%`r`ndeltaX=%deltaX% deltaY=%deltaY%
Edit.=Text "`r`n`r`n"
if(deltaX||deltaY)
{
PrependEdit(Edit)
}
ToolTip,%Text%
return 0
}
PrependEdit(ByRef Text)
{
DllCall("SendMessage","UPtr",Gui1_Edit1_hWnd,"UInt",0x00B1,"UPtr",0,"Ptr",0,"Ptr") ; EM_SETSEL
DllCall("SendMessage","UPtr",Gui1_Edit1_hWnd,"UInt",0x00C2,"UPtr",FALSE,"Ptr",&Text,"Ptr") ; EM_REPLACESEL
}
FormatMessage(dwMessageId)
{
static Buffer
VarSetCapacity(Buffer,nSize:=3000)
DllCall("FormatMessage","UInt",0x00001000,"UPtr",0,"UInt",dwMessageId,"UInt",0,"Str",Buffer,"UInt",nSize//2,"UPtr",0)
return RegExReplace(Buffer,"(.*)[`r`n]*$","$1")
}