Home Forums Software Development C# WPF project Question Reply To: C# WPF project Question

#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);
    }
}