2

I'm busy making a application where i can use the Leap as a mouse. I'm making a WPF application with C# and XAML. I allready can move the cursor, but i have problems making a function to activate the left mouse button. Can someone help me with this problem? I need to activate buttons created in XAML. Another solution could be a function that activates a button when de Leap cursor is on the button for like 3 seconds. I can't find any examples on the Internet. Does someone have a simple basic program or example for me? Please help!

Here is a link to the application i allready have. Maybe it helps https://www.dropbox.com/sh/kp51hdbhcacaky7/pdinDQpA-6

  • This is the cost of being on the bleeding edge. Can you not translate something like a finger pinch into a left mouse button click? Or is the problem causing what WPF thinks is a click? – Adam Houldsworth Sep 18 '13 at 09:51
  • My application can recognize gestures like swipes or taps. But these gestures can't be programmed as mousclick because making the gesture means that the mouse will move and will no longer be on the button. I can hold the leap cursor on a button but don't know how to activate it. But with the real mouse it can be activated! (i have two cursors). Maybe i cant program mouse functiones behind the leap cursor? I don't really know which part the problem is. It could be the Leap SDK, XAML or WPF. Maybe it is not yet possible with the Leap SDK? – user2790929 Sep 18 '13 at 10:07
  • If you want it to work like a mouse does, you can send click input events to the OS which then generates ordinary mouse events. The Windows API SendInput function can do this (http://msdn.microsoft.com/en-us/library/windows/desktop/ms646310(v=vs.85).aspx) -- but I don't have the knowledge to say whether that is available in C#/XAML. Otherwise, you would need a function that finds which control is under your cursor and activate it programatically. – Charles Ward Sep 23 '13 at 19:13

2 Answers2

1

About the "mouse over button" thing - u can try this solution (worked for me):

  1. create hover event for buttons (mouse entered / leave)
  2. create a bool flag for like "isHovered" (true if hovered, false if not)
  3. start a DispacherTimer, set it's Tick (3 sec?)
  4. on Tick do mouse click (previous answer)

hope it halped :)

0

try this:

[DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
    public static extern void mouse_event(int dwFlags, int dx, int dy, int cButtons, int dwExtraInfo);

    private const int MOUSEEVENTF_LEFTDOWN = 0x02;
    private const int MOUSEEVENTF_LEFTUP = 0x04;
    private const int MOUSEEVENTF_RIGHTDOWN = 0x08;
    private const int MOUSEEVENTF_RIGHTUP = 0x10;

    public static void DoMouseClick()
    {
            Point mousePoint = GetMousePosition();
            mouse_event(MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP, (int)mousePoint.X, (int)mousePoint.Y, 0, 0);
    }