您的位置:首页 > 其它

键盘控制鼠标的方法

2016-11-30 10:44 309 查看
#include <Windows.h>

void MoveMouseCursor(int dx, int dy)
{
POINT point;
::GetCursorPos(&point);
point.x += dx;
point.y += dy;
::SetCursorPos(point.x, point.y);
}

VOID CALLBACK timer_proc(HWND hw, UINT msg, UINT_PTR eventx, DWORD tick)
{
if(5555)
{
do
{
BOOL bUdLr = FALSE;

if(::GetAsyncKeyState(VK_UP) &&::GetAsyncKeyState(VK_F2))
{
MoveMouseCursor(0, -8);
bUdLr = TRUE;
}

if(::GetAsyncKeyState(VK_DOWN) &&::GetAsyncKeyState(VK_F2))
{
MoveMouseCursor(0, 8);
bUdLr = TRUE;
}

if(::GetAsyncKeyState(VK_LEFT) &&::GetAsyncKeyState(VK_F2))
{
MoveMouseCursor(-8, 0);
bUdLr = TRUE;
}

if(::GetAsyncKeyState(VK_RIGHT) &&::GetAsyncKeyState(VK_F2))
{
MoveMouseCursor(8, 0);
bUdLr = TRUE;
}

if(::GetAsyncKeyState(VK_F2) &&::GetAsyncKeyState(VK_INSERT))
{
POINT p;
::GetCursorPos(&p);
mouse_event(MOUSEEVENTF_LEFTDOWN, p.x, p.y, 0, 0);
::Sleep(300);
mouse_event(MOUSEEVENTF_LEFTUP, p.x, p.y, 0, 0);
}

if(::GetAsyncKeyState(VK_F2) &&::GetAsyncKeyState(VK_HOME))
{
POINT p;
::GetCursorPos(&p);
mouse_event(MOUSEEVENTF_RIGHTDOWN, p.x, p.y, 0, 0);
::Sleep(300);
mouse_event(MOUSEEVENTF_RIGHTUP, p.x, p.y, 0, 0);
}
}
while(0);
}
}

int __stdcall WinMain(HINSTANCE hInstance,   HINSTANCE hPrevInstance,   LPSTR lpCmdLine,   int nShowCmd)
{
::SetTimer(NULL, 5555, 1, timer_proc);
MSG msg;

while(::GetMessage(&msg, 0, 0, 0))
{
::TranslateMessage(&msg);
::DispatchMessage(&msg);
}

return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息