1
我打得周圍與Windows的問題掛鉤的時刻。我建立了一個全球低級別的鼠標鉤 ,我想反轉mousemovement。對於這個我有幾個問題(我希望這是正確的,我的英語不是很好,對不起)。第一個是修改lParam參數,並與CallNextHookEx方法函數轉發:與修改鼠標移動
LRESULT CALLBACK MouseInvertProc(int nCode, WPARAM wParam, LPARAM lParam)
{
MSLLHOOKSTRUCT* ms = NULL;
int dx = 0; //delta x
int dy = 0; //delta y
if(nCode == HC_ACTION)
{
if(wParam == WM_MOUSEMOVE)
{
ms = (MSLLHOOKSTRUCT*)lParam;
dx = ms->pt.x - g_oldMousePos.x;
dy = ms->pt.y - g_oldMousePos.y;
ms->pt.x = ms->pt.x - 2 * dx;
ms->pt.y = ms->pt.y - 2 * dy;
GetCursorPos(&g_oldMousePos);
return CallNextHookEx(g_MouseInvertHook,nCode,wParam, (LPARAM)ms);
}
else
return CallNextHookEx(g_MouseInvertHook, nCode, wParam, lParam);
}
return CallNextHookEx(g_MouseInvertHook, nCode, wParam, lParam);
}
但這沒有任何效果可言。有人知道爲什麼嗎?
第二次嘗試是提供一個輸入與修改後的mousecoordinates:
LRESULT CALLBACK MouseInvertProc(int nCode, WPARAM wParam, LPARAM lParam)
{
MSLLHOOKSTRUCT* ms = NULL;
int dx = 0; //delta x
int dy = 0; //delta y
if(nCode == HC_ACTION)
{
if(wParam == WM_MOUSEMOVE)
{
ms = (MSLLHOOKSTRUCT*)lParam;
dx = ms->pt.x - g_oldMousePos.x;
dy = ms->pt.y - g_oldMousePos.y;
ms->pt.x = ms->pt.x - 2 * dx;
ms->pt.y = ms->pt.y - 2 * dy;
GetCursorPos(&g_oldMousePos);
if(!g_artificialma) //g_artificialma is true when i created a artificial mouse input.
{
g_artificialma = true;
mouse_event(MOUSEEVENTF_MOVE | MOUSEEVENTF_ABSOLUTE, ms->pt.x, ms->pt.y, NULL, NULL);
return 1;
}
else
{
g_artificialma = false;
return CallNextHookEx(g_MouseInvertHook, nCode, wParam, lParam);
}
}
else
return CallNextHookEx(g_MouseInvertHook, nCode, wParam, lParam);
}
return CallNextHookEx(g_MouseInvertHook, nCode, wParam, lParam);
}
隨着g_artificialma可變我想阻止一個無限循環,因爲當我打電話mouse_event的HOOKPROC被調用。
但這樣我讓我的鼠標卡在我的屏幕左上角。
的最後一次嘗試是簡單地調用SetCursorPos函數:
LRESULT CALLBACK MouseInvertProc(int nCode, WPARAM wParam, LPARAM lParam)
{
MSLLHOOKSTRUCT* ms = NULL;
int dx = 0; //delta x
int dy = 0; //delta y
if(nCode == HC_ACTION)
{
if(wParam == WM_MOUSEMOVE)
{
ms = (MSLLHOOKSTRUCT*)lParam;
dx = ms->pt.x - g_oldMousePos.x;
dy = ms->pt.y - g_oldMousePos.y;
ms->pt.x = ms->pt.x - 2 * dx;
ms->pt.y = ms->pt.y - 2 * dy;
GetCursorPos(&g_oldMousePos);
SetCursorPos(ms->pt.x, ms->pt.y);
}
else
return CallNextHookEx(g_MouseInvertHook, nCode, wParam, lParam);
}
return CallNextHookEx(g_MouseInvertHook, nCode, wParam, lParam);
}
這工作得很好,但在例如3D應用,這引起了怪異的鼠標移動
,我認爲這種方式實在是太醜了,因爲我阻止其他應用程序安裝的鉤子。
那麼你有什麼建議來解決,在一個良好的工作和乾淨的方式(也許沒有窗戶鉤)?
EEEH,我剛看到這個問題是10個月大。我的答案可能沒有太多意義。 – Hallion