Home Forums Software Development C# WPF project Question

Tagged: , ,

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #2104
    JiWoong Kim
    Participant

    Are there any ways to move mouse cursor where user gaze at?
    or know the X,Y position where user gaze at?

    I want some sample code to understand please…

    #2108
    Robert [Tobii]
    Participant

    Hi,

    Here is an example of a simple C# command line application that just moves the mouse cursor around to where you are looking. Note that, because of the characteristics of the eyes, it is hard to build a user interface based on just replacing the mouse cursor with the gaze position. But the code below should give you something to start with.

    using EyeXFramework;
    using System;
    using System.Runtime.InteropServices;
    using Tobii.EyeX.Framework;
    
    public static class Program
    {
        [DllImport("user32.dll")]
        static extern bool SetCursorPos(int X, int Y);
    
        public static void Main(string[] args)
        {
            var eyeXHost = new EyeXHost();
            eyeXHost.Start();
    
            var lightlyFilteredGazeDataStream = eyeXHost.CreateGazePointDataStream(GazePointDataMode.LightlyFiltered);
            lightlyFilteredGazeDataStream.Next += (s, e) => MoveMouse(e.X, e.Y);
    
            var eyePositionDataStream = eyeXHost.CreateEyePositionDataStream();
            //TODO: Listen for blinks using the eye position data stream
    
            // Let it run until a key is pressed.
            Console.In.Read();
    
            lightlyFilteredGazeDataStream.Dispose();
            eyePositionDataStream.Dispose();
            eyeXHost.Dispose();
        }
    
        private static void MoveMouse(double x, double y)
        {
            // TODO: Filtering of gaze point data
            SetCursorPos((int)x, (int)y);
        }
    }
    #2112
    JiWoong Kim
    Participant

    Thanks 🙂 I tried and can get position at command line application. But it doesn’t work at wpf project. And also I tried other codes at C# command line application and C but, I don’t know why some codes doesn’t work at wpf project. Do you have any idea about this?

    #2114
    JiWoong Kim
    Participant

    And one more question 🙂 Mouse cursor is shaking to much and I don’t know why. Do you have any idea?

    #2118
    Jenny [Tobii]
    Participant

    Hi there,

    How have you implemented the code in WPF? There is no Main method the same way in a WPF project, so the sample code above cannot be copy-and-pasted as is.

    Regarding the shaking – this is anticipated if you do not do any additional filtering of the data. The data is only lightly filtered when it comes from the EyeX Engine. You need to apply a suitable filtering for your purposes. In your case something that averages the data to make the movement of the cursor smoother. You should put your filtering algorithm where the “TODO: Filtering of gaze point data” is in the MoveMouse method in the code sample above.

    #2816
    yagoub
    Participant

    but how can we used it in WPF Jenny ,I need this plaise ,,,

    Thank’s

    #2823
    Jenny [Tobii]
    Participant

    Hi Yagoub,

    Please, check out the WPF sample UserPresenceWpf in the EyeX SDK for .Net:
    There a WpfEyeXHost is created and started in App.xaml.cs. Then a MainWindowModel is created supplying the EyeX host to the constructor. Finally, the window model is supplied as the data context when creating the MainWindow. This way, the EyeX host will be available for usage in the MainWindowModel class.

    With a corresponding design you can set up the data stream and the event handling in the constructor of your MainWindowModel. Make sure to dispose the EyeX host and unsubscribe from the event handling at application teardown. Note also that the data stream events will arrive on a background thread, so make sure to switch to run on the main UI thread as needed.

Viewing 7 posts - 1 through 7 (of 7 total)
  • You must be logged in to reply to this topic.