c# - Mouse move code snippet doesnt work with Kinect sdk2.0 -
although getting values of cursorx, cursory there no movement of mouse cursor. missing anything?
joint hand = helper.handright; cameraspacepoint position = hand.position; depthspacepoint handpt = _sensor.coordinatemapper.mapcamerapointtodepthspace(position); point relativepoint = new point( handpt.x * (1920 / _sensor.depthframesource.framedescription.width), handpt.y * (1080 / _sensor.depthframesource.framedescription.height) ); cursorx = (int)relativepoint.x; cursory = (int)relativepoint.y; nativemethods.sendmouseinput(cursorx, cursory, (int)systemparameters.primaryscreenwidth, (int)systemparameters.primaryscreenheight, leftclick); public static class nativemethods { public const int inputmouse = 0; public const int mouseeventmove = 0x01; public const int mouseeventleftdown = 0x02; public const int mouseeventleftup = 0x04; public const int mouseeventrightdown = 0x08; public const int mouseeventrightup = 0x10; public const int mouseeventmiddledown = 0x0020; public const int mouseeventmiddleup = 0x0040; public const int mouseeventabsolute = 0x8000; public const int mouseeventwheelscroll = 0x0800; public const int mouseeventwheelhscroll = 0x1000; private static bool lastleftdown = false; [dllimport("user32.dll", setlasterror = true)] private static extern uint sendinput(uint numinputs, input[] inputs, int size); public static void sendmouseinput(int positionx, int positiony, int maxx, int maxy, bool leftdown) { if (positionx > int.maxvalue) throw new argumentoutofrangeexception("positionx"); if (positiony > int.maxvalue) throw new argumentoutofrangeexception("positiony"); input[] = new input[4]; // move mouse position specified i[0] = new input(); i[0].type = inputmouse; i[0].mouseinput.x = (positionx * 65535) / maxx; i[0].mouseinput.y = (positiony * 65535) / maxy; i[0].mouseinput.flags = mouseeventabsolute | mouseeventmove; // determine if need send mouse down or mouse event if (!lastleftdown && leftdown) { i[1] = new input(); i[1].type = inputmouse; i[1].mouseinput.flags = mouseeventleftdown; lastleftdown = true; } else if (lastleftdown && !leftdown) { i[1] = new input(); i[1].type = inputmouse; i[1].mouseinput.flags = mouseeventleftup; lastleftdown = false; } // send off uint result = sendinput(2, i, marshal.sizeof(i[0])); if (result == 0) throw new win32exception(marshal.getlastwin32error()); } } }
Comments
Post a Comment