鍵盤控制鼠標的方法

#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;
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章