Home › Forums › Software Development › C# WPF project Question
Tagged: c++, gaze point, mouse
- This topic has 6 replies, 4 voices, and was last updated 9 years, 8 months ago by Jenny [Tobii].
- AuthorPosts
- 22/11/2014 at 16:14 #2104JiWoong KimParticipant
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…
24/11/2014 at 12:38 #2108Robert [Tobii]ParticipantHi,
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); } }
25/11/2014 at 08:34 #2112JiWoong KimParticipantThanks 🙂 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?
25/11/2014 at 12:28 #2114JiWoong KimParticipantAnd one more question 🙂 Mouse cursor is shaking to much and I don’t know why. Do you have any idea?
27/11/2014 at 11:39 #2118Jenny [Tobii]ParticipantHi 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.
07/04/2015 at 13:29 #2816yagoubParticipantbut how can we used it in WPF Jenny ,I need this plaise ,,,
Thank’s
08/04/2015 at 09:43 #2823Jenny [Tobii]ParticipantHi 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.
- AuthorPosts
- You must be logged in to reply to this topic.