Custom Search

Monday, June 22, 2009

Mouse driver for C++

Recently, there has been a lot of hype about Multi touch and there are x companies interested in purchasing my multi touch screen.
One company requested that I enable a single touch function to control the mouse.

Below is the mouse driver code:

Settings: Ignore Specific Library libcmt.lib //if you get the warning /nodefaultlib...

Use of MFC: Use MFC in a Static Library. //Shared may give some problems.

in stdafx.h

#ifndef _WIN32_WINNT
#define _WIN32_WINNT 0x0501
#endif



#include windows.h
// Get total screen coordinates
int screen_x = GetSystemMetrics(SM_CXSCREEN);
int screen_y = GetSystemMetrics(SM_CYSCREEN);
int x,y;
x = 150 *(65335/screen_x);
y = 150 *(65335/screen_y);

INPUT reset;
reset.type = INPUT_MOUSE;
reset.mi.dx = x;
reset.mi.dy = y;
reset.mi.mouseData = 0;
reset.mi.dwFlags = ( MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_MOVE );

//reset1.mi.dwFlags = ( MOUSEEVENTF_LEFTDOWN );//to control other mouse functions.
//reset2.mi.dwFlags = ( MOUSEEVENTF_LEFTUP );

SendInput(1,&reset,sizeof(reset));

No comments: