Mouse hook lparam in 64bit

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
scsnake
Posts: 23
Joined: 05 Aug 2015, 03:19

Mouse hook lparam in 64bit

14 May 2017, 01:03

I'm transforming my scripts to be compatible with 64-bit windows, using AutoHotkey_L (32bit, unicode). I noticed that the mouse coordinate from lParam of MouseHook was wrong in Windows 10 64bit (in Parallel Desktop), which was ok in Win 7 (32bit), using AHK_L (32bit and 64bit both). Is there anything need to be modified? Is there any limit on hook/DllCall if I use AHK_L (32bit) in 64-bit OS? For example, is 32bit AHK capable of "OpenProcess" of a 64bit process?

Code: Select all

CoordMode,mouse,Screen

hHookMouse := SetWindowsHookEx(WH_MOUSE_LL   := 14, RegisterCallback("MouseHook", "Fast"))
return

esc::ExitApp

MouseHook(nCode, wParam, lParam){
	VarSetCapacity(lpPoint,8)
	,DllCall("GetCursorPos", "Ptr", &lpPoint)
	,lx := NumGet(lpPoint, 0, "Int")
	,ly := NumGet(lpPoint, 4, "Int")
	,mx := NumGet(lParam+0, 0, "Int")
	,my := NumGet(lParam+0, 4, "Int")
	MouseGetPos,x,y
	ToolTip % lx "," ly "`n" mx "," my "`n" x "," y ; mx/my is different from the others in 64bit Windows
	CallNextHookEx(nCode, wParam, lParam)
}
	
	
SetWindowsHookEx(idHook, pfn)
{
   Return DllCall("SetWindowsHookEx", "int", idHook, "Ptr", pfn, "Ptr", DllCall("GetModuleHandle", "Ptr", 0 ,"Ptr"), "Uint", 0, "Ptr")
}

CallNextHookEx(nCode, wParam, lParam, hHook = 0)
{
   Return DllCall("CallNextHookEx", "Ptr", hHook, "int", nCode, "UPtr", wParam, "Ptr", lParam, "Ptr")
}
Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: Mouse hook lparam in 64bit

14 May 2017, 03:53

Your code seems fine to me.
Note that the hook coordinates are given in in per-monitor-aware screen coordinate, source and
LowLevelMouseProc callback function wrote: The system calls this function every time a new mouse input event is about to be posted into a thread input queue.
source
So the hook gives you the new coordinates, which are about to be set. You can change your callback function to this, to observe this,

Code: Select all

MouseHook(nCode, wParam, lParam){
	static px, py						; p as in previous.
	VarSetCapacity(lpPoint,8)
	,DllCall("GetCursorPos", "Ptr", &lpPoint)
	,lx := NumGet(lpPoint, 0, "Int")
	,ly := NumGet(lpPoint, 4, "Int")
	,mx := NumGet(lParam+0, 0, "Int")
	,my := NumGet(lParam+0, 4, "Int")
	
	MouseGetPos,x,y
	ToolTip % lx "," ly "`n" mx "," my "`n" x "," y  "`n" px "," py ; mx/my is different from the others in 64bit Windows
	px:=mx,py:=my
	CallNextHookEx(nCode, wParam, lParam)
}
Cheers.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: joefiesta and 290 guests