Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7278267
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T22:51:05+00:00 2026-05-28T22:51:05+00:00

I am trying to do something like Kinect adventures with Kinect SDK i.e. when

  • 0

I am trying to do something like Kinect adventures with Kinect SDK i.e. when the mouse stays in a certain area for a specific period of time, the native click event is to be fired.
The problem is that I do not get the expected results, since I get random clicking most times. I tried to check with breakpoints etc.
Most often, when my hand is not visible, the cursor goes to the corner of the screen and starts clicking. This is most probably because Math.Abs(lastX - cursorX) < threshold sets to true.

I have tried changing the threshold values to 200, but it fires a click st the start, and afterwards I am not get expected left clicks, when I hold the cursor in a certain position for some time. Any suggestions would be greatly appreciated. Here’s the code:

//SkeletonFrameReadyevent

foreach (SkeletonData sd in e.SkeletonFrame.Skeletons)
{
    if (sd.TrackingState == SkeletonTrackingState.Tracked)
    {
        // make sure both hands are tracked
        if (sd.Joints[JointID.HandLeft].TrackingState == JointTrackingState.Tracked &&
            sd.Joints[JointID.HandRight].TrackingState == JointTrackingState.Tracked)
        {
            int cursorX, cursorY;

        // get the left and right hand Joints
        Joint jointRight = sd.Joints[JointID.HandRight];
        Joint jointLeft = sd.Joints[JointID.HandLeft];

        // scale those Joints to the primary screen width and height
        Joint scaledRight = jointRight.ScaleTo((int)SystemParameters.PrimaryScreenWidth, (int)SystemParameters.PrimaryScreenHeight, SkeletonMaxX, SkeletonMaxY);
        Joint scaledLeft = jointLeft.ScaleTo((int)SystemParameters.PrimaryScreenWidth, (int)SystemParameters.PrimaryScreenHeight, SkeletonMaxX, SkeletonMaxY);

        // figure out the cursor position based on left/right handedness

            cursorX = (int)scaledRight.Position.X;
            cursorY = (int)scaledRight.Position.Y;
        //default false, for mouse move, set to true for mouse click
        bool leftClick;

        if (lastY == 0)
        {
            lastX = cursorX;
            lastY = cursorY;
        }

        leftClick = false;
        if (Math.Abs(lastX - cursorX) < threshold && Math.Abs(lastY - cursorY) < threshold)
        {
            if (Math.Abs(lastClick.Subtract(DateTime.Now).TotalSeconds) > 1)
            {
                //Mouse click here
                leftClick = true;
            }
        }

        //Mouse click when leftDown is true, else Mousemove
        NativeMethods.SendMouseInput(cursorX, cursorY, (int)SystemParameters.PrimaryScreenWidth, (int)SystemParameters.PrimaryScreenHeight, leftClick);
        return;
        }
    }
}

NativeMthods.cs class has this function:

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[] i = new Input[2];

    // move the mouse to the 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 we need to send a mouse down or mouse up event
    if(leftDown)
    {
        i[1] = new Input();
        i[1].Type = InputMouse;
        i[1].MouseInput.Flags = MouseEventLeftDown;
        i[1].MouseInput.Flags |= MouseEventLeftUp;
    }

    // send it off
    uint result = SendInput(2, i, Marshal.SizeOf(i[0]));
    if(result == 0)
        throw new Win32Exception(Marshal.GetLastWin32Error());
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T22:51:06+00:00Added an answer on May 28, 2026 at 10:51 pm

    Try something like this:

        public class myMouseClass: IMessageFilter //Must implement IMessageFilter
        {
            [DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
            public static extern void mouse_event(long dwFlags, long dx, long dy, long cButtons, long dwExtraInfo);
    
            //Constants 
            private const int MOUSEEVENTF_LEFTDOWN = 0x02;
            private const int MOUSEEVENTF_LEFTUP = 0x04;
            private const int MOUSEEVENTF_RIGHTDOWN = 0x08;
            private const int MOUSEEVENTF_RIGHTUP = 0x10;
            private const int WM_MOUSEMOVE = 0x0200;
    
            private int Threshold = 20; //how far the mouse should move to reset timer
            private int StartLocationX = 0; //stores starting X value
            private int StartLocationY = 0; //stores starting Y value
            private Timer timerHold = new Timer(); //timer to trigger mouse click
    
            //Start Mouse monitoring by calling this. This will also set the timer.     
            private void StartFilterMouseEvents()
            {
    
                timerHold.Interval = 1000; //how long mouse must be in threshold.
                timerHold.Tick = new EventHandler(timerHold_Tick);
                Application.AddMessageFilter((IMessageFilter) this);
            }
            //Stop Mouse monitoring by calling this and unset the timer.
            private void StopFilterMouseEvents()
            {
                timerHold.Stop();
                timerHold -= timerHold_Tick;
                Application.RemoveMessageFilter((IMessageFilter) this);
            }
            //This will start when Application.AddMessageFilter() is called
            public bool PreFilterMessage(ref Message m)
            {
                if (m.Msg == WM_MOUSEMOVE)
                {
                    if((Cursor.Position.X > StartLocationX + 20)||(Cursor.Position.X > StartLocationX - 20))&&
                           ((Cursor.Position.Y > StartLocationY + 20)||(Cursor.Position.Y > StartLocationY - 20))
                           {
                                timerHold.Stop(); //stops timer if running
                                timerHold.Start(); //starts it again with new position.
                                StartLocationX = Cursor.Position.X;
                                StartLocationY = Cursor.Position.Y;
                           }
                }
                return false;
            }
            //This event gets fired when the timer has not been reset for 1000ms
            public void timerHold_Tick(object sender, EventArgs e)
            {
                mouse_event(MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
            }
    
          }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How to serialize date time object? I am trying something like this. my_date_time =
I'm trying something like this Output.py print Hello Input.py greeting = raw_input(Give me the
I'm trying something like this, but this example does not work. jsObj = {};
I'm trying something like this: [ServiceContract ( CallbackContract = typeof (CallbackContract_1), CallbackContract = typeof
As the title goes I am trying something like $(ul li:nth-child(' + xx +
Is it possible to set for(AssociatedControlID) attribute using jQuery? I am trying something like
I'm trying to implement something like this: <div> <table> <thead> <tr> <td>Port name</td> <td>Current
I am trying to so something like Database Design for Tagging , except each
I've trying to achieve something like this: class Base { public: Base(string S) {
I'm trying to do something like this in Java: public static <T> T foo()

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.