Domanda

I wrote touchless mouse for the LeapMotion device (see Code) The problem is that the mouse listener is only active if the winform is on top and has focus. If it lost the focus the program cannot control the cursor. I tried to set the "always ontop" or " topmost" property on "true".

public Form1()
{
    InitializeComponent();
    this.ShowInTaskbar = false;
    this.Opacity = 0;
    this.TopMost = true;
}

Yet, this does not alter the fact that when the window lost its focus it stop to control the cursor. How can I implement it that the window or program is active and moves the cursor around even when it has no focus?

È stato utile?

Soluzione

By default, the Leap Motion service stops sending frames to non-foreground applications. This is to prevent unintended input to your application when the user is interacting with a different application.

To override this, you can set a policy flag to enable background frames:

controller.SetPolicyFlags(Controller.PolicyFlag.POLICYBACKGROUNDFRAMES);

When this is set (and the user hasn't disabled background apps in their Leap Motion control panel) your app will receive background frames when it is in the background and the current foreground application is NOT Leap-enabled.

Altri suggerimenti

First of all, you need to pass the following policy flag to the controller. It allows the controller to receive frames even when your application is in the background.

var controller = new Controller();
controller.SetPolicyFlags(Controller.PolicyFlag.POLICYBACKGROUNDFRAMES);

Note that according to the SDK, you are only requesting this policy and the change may not be immediate. You can learn more about it here.

Lastly, the 'Allow Background Apps' checkbox in the Leap Motion control panel needs to be ticked.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top