From 0d1b9c6063805958e075b1121227d985a065c6d6 Mon Sep 17 00:00:00 2001 From: fcolin Date: Tue, 22 Sep 2009 09:00:57 +0000 Subject: mise a jour des projets --- IvyCursor/IvyCursor.cpp | 167 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 166 insertions(+), 1 deletion(-) (limited to 'IvyCursor/IvyCursor.cpp') diff --git a/IvyCursor/IvyCursor.cpp b/IvyCursor/IvyCursor.cpp index 558d074..cb91542 100644 --- a/IvyCursor/IvyCursor.cpp +++ b/IvyCursor/IvyCursor.cpp @@ -6,6 +6,9 @@ #include #include #include +#include + +#include "options.h" #include "IvyCursor.h" #define MAX_LOADSTRING 100 @@ -75,12 +78,168 @@ void ivyCursorClick(IvyApplication *app, void *user_data, int argc, const char * _RPT3(_CRT_WARN,"ivyCursorClick can click to x=%d y=%d error=%d\n",x,y,GetLastError()); } } +void SendInput ( DWORD flags, float x, float y , int wheel ) +{ + UINT nb; + INPUT Inputs; + + Inputs.type = INPUT_MOUSE; + Inputs.mi.dwFlags = flags; + Inputs.mi.mouseData = wheel; + Inputs.mi.time = 0; // system provide it + Inputs.mi.dx = (int)(65535 * x ); + Inputs.mi.dy = (int)(65535 * y ); + + nb = SendInput( 1, &Inputs, sizeof(INPUT)); + + if ( nb != 1 ) + { + _RPT3(_CRT_WARN,"ivyPointerEvent can move to x=%d y=%d error=%d\n",x,y,GetLastError()); + } +} +void ivyPointerEvent(IvyApplication *app, void *user_data, int argc, const char **argv) +{ + int x = atoi(*argv++); + int y = atoi(*argv++); + int presure = atoi(*argv++); + int tilt_x = atoi(*argv++); + int tilt_y = atoi(*argv++); + int wheel = atoi(*argv++); + int predicted_x = atoi(*argv++); + int predicted_y = atoi(*argv++); + const char *type = *argv++; + int serial_number = atoi(*argv++); + float time = atof(*argv++); + float hires_x = atof(*argv++); + float hires_y = atof(*argv++); + const char *proximity = *argv++; // (In|Out|unchanged) + + // hack for tablet PC + if ( serial_number ==0 ) + { + hires_x *= 86800 / 1400; + hires_y *= 65000 / 1050; + } + + SendInput ( MOUSEEVENTF_WHEEL | MOUSEEVENTF_MOVE | MOUSEEVENTF_ABSOLUTE, hires_x, hires_y , wheel ); + + + +} +void ivyButtonEvent(IvyApplication *app, void *user_data, int argc, const char **argv) +{ + static int bt_down = 0; + int button = atoi(*argv++); + const char *status = *argv++ ; //(up|down) + int x = atoi(*argv++); + int y = atoi(*argv++); + int presure = atoi(*argv++); + int tilt_x = atoi(*argv++); + int tilt_y = atoi(*argv++); + int wheel = atoi(*argv++); + int predicted_x = atoi(*argv++); + int predicted_y = atoi(*argv++); + const char *type = *argv++; + int serial_number = atoi(*argv++); + float time = atof(*argv++); + float hires_x = atof(*argv++); + float hires_y = atof(*argv++); + const char *proximity = *argv++; // (In|Out|unchanged) + + // hack for tablet PC + if ( serial_number ==0 ) + { + hires_x *= 86800 / 1400; + hires_y *= 65000 / 1050; + } + if ( hires_x < 0 || hires_y < 0 ) + { + if ( *status == 'u' && bt_down ) + { + SendInput ( MOUSEEVENTF_LEFTUP, hires_x, hires_y , wheel ); + bt_down = 0; + } + + } + else + { + if ( (*status) == 'd' ) + { + SendInput ( MOUSEEVENTF_WHEEL | MOUSEEVENTF_MOVE | MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_LEFTDOWN , hires_x, hires_y , wheel ); + bt_down = 1; + } + else + { + SendInput ( MOUSEEVENTF_WHEEL | MOUSEEVENTF_MOVE | MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_LEFTUP , hires_x, hires_y , wheel ); + bt_down = 0; + } + } + +} +void ivyPadEvent(IvyApplication *app, void *user_data, int argc, const char **argv) +{ + int button = atoi(*argv++); + const char *status = *argv++ ; //(up|down) + int time = atoi(*argv++); + +} +void ivySliderEvent(IvyApplication *app, void *user_data, int argc, const char **argv) +{ + int value = atoi(*argv++); + const char* side = *argv++ ; // (left|right) + int time = atoi(*argv++); +} + int APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow) { MSG msg; + int optchar; + const char * optarg; + const char * ivybus = NULL; + const char * acc = "bordeaux"; + const char * wp = "WP1"; + const char * role = "TC"; + + int errors = 0, ngroups = 0; + // read command line + + static const char * optv[] = { + "H|help", + "a:acc ", + "w:wp ", + "r:role ", + "b:bus ", + NULL + } ; + Options opts("ivycursor", optv); + OptStrTokIter iter(lpCmdLine); + + while( optchar = opts(iter, optarg) ) { + switch (optchar) { + case 'H' : + opts.usage(std::cout, "ivycursor ..."); + exit(0); + break; + case 'a' : + acc = optarg; break; + case 'w' : + wp = optarg; break; + case 'r' : + role = optarg; break; + case 'b' : + ivybus = optarg; break; + default : ++errors; break; + } //switch + } + + if (errors) { + opts.usage(std::cerr, "ivycursor ..."); + exit(1); + } + // Initialise les chaînes globales LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING); LoadString(hInstance, IDC_IVYCURSOR, szWindowClass, MAX_LOADSTRING); @@ -106,7 +265,13 @@ int APIENTRY _tWinMain(HINSTANCE hInstance, bus = new Ivy("IvyCursor", "IvyCursor Ready", 0, FALSE ); bus->BindMsg(BUS_CALLBACK(ivyCursorMouve,0),"^Cigale SetCursorPosition x=([0-9.]+) y=([0-9.]+)"); bus->BindMsg(BUS_CALLBACK(ivyCursorClick,0),"^Cigale CursorSelectEvent x=([0-9.]+) y=([0-9.]+)"); - bus->start( 0 ); + + bus->BindMsg(BUS_CALLBACK(ivyPointerEvent,0), "^pointer_event device_id=%s:%s:%s x=([-0-9]+) y=([-0-9]+) presure=([-0-9]+) tilt_x=([-0-9]+) tilt_y=([-0-9]+) wheel=([-0-9]+) predicted_x=([-0-9]+) predicted_y=([-0-9]+) type=(.*) serial_number=([-0-9]+) time=([-.0-9]+) hires_x=([-.0-9]+) hires_y=([-.0-9]+) proximity=(In|Out|unchanged)", acc, wp, role ); + bus->BindMsg(BUS_CALLBACK(ivyButtonEvent,0), "^button_event device_id=%s:%s:%s button=([-.0-9]+) status=(up|down) x=([-0-9]+) y=([-0-9]+) presure=([-0-9]+) tilt_x=([-0-9]+) tilt_y=([-0-9]+) wheel=([-0-9]+) predicted_x=([-0-9]+) predicted_y=([-0-9]+) type=(.*) serial_number=([-0-9]+) time=([-0-9]+) hires_x=([-.0-9]+) hires_y=([-.0-9]+) proximity=(In|Out|unchanged)", acc, wp, role ); + bus->BindMsg(BUS_CALLBACK(ivyPadEvent,0), "^pad_event device_id=%s:%s:%s button=([0-9]+) status=(up|down) time=([-0-9]+)", acc, wp, role); + bus->BindMsg(BUS_CALLBACK(ivySliderEvent,0), "^slider_event device_id=%s:%s:%s value=([-0-9]+) side=(left|right) time=([-0-9]+)", acc, wp, role); + + bus->start( ivybus ); // Boucle de messages principale : while (GetMessage(&msg, NULL, 0, 0)) -- cgit v1.1