windows - Hooking mouse input and moving cursor -
i'm setting global mouse hook:
hmousehook = setwindowshookex(wh_mouse_ll, llmouseproc, getmodulehandle(0), 0);
and hooking mouse move messages , moves mouse cursor.
lresult callback llmouseproc(int ncode, wparam wparam, lparam lparam) { lpmsllhookstruct lpmh = reinterpret_cast<lpmsllhookstruct>(lparam); uint nmsg = static_cast<uint>(wparam); point ptscreen = { 0 }; if (ncode >= 0) { ptscreen = lpmh->pt; if (wm_mousemove == nmsg) { // ptscreen coordinates receiving in physical units (pixels) // convert them logical point logpos = { ptscreen.x, ptscreen.y }; convertphysicaltological(&logpos); // move mouse cursor new position // setcursotpos() requires coordinates in logical units setcursorpos(logpos.x, logpos.y); // don't want propagate message return 1l; } } return 0l; }
everything works if scale factor 1.0... ok how works. move mouse physical coordinate [29,94], let say, our scale factor 1.5, logical coordinates [19,62]. call
setcursorpos(19, 62);
it triggers sending wm_mousemove , somewhere internally converts our logical coordinates physical 19 * 1.5 = 28, 62 * 1.5 = 93, our new input coordinates [28,93] instead of [29,94]. we're repeating everything, converting [28,93] logical [18, 62] , call
setcursorpos(18, 62);
and on...
so, know calling setcursorpos() llmouseproc isn't correct , i'm trying find solution - there proper way it?
p.s.> clipcursor() doesn't because calls setcursorpos()
thank you!
Comments
Post a Comment