Home › Forums › Software Development › using dll in Delphi, control the mouse
Tagged: delphi, mouse control
- This topic has 11 replies, 5 voices, and was last updated 8 years ago by Alan McNicol.
- AuthorPosts
- 14/11/2014 at 15:02 #2014GerardParticipant
Hi,
Has anyone by any chance translated the c header files to Delphi import units and is willing to share them?
I need to write a simple (I hope) program to move the mouse cursor to the current (filtered) gaze position. That is, a first application I would like to use the eye-tracker for is an application I wrote in which an object is moved across the screen with the eyes and this object is coupled to the position of the (invisible) mouse cursor. If someone already has software to control the mouse using EyeX and is willing to share that would of course be great too.
Kind regards,
Gerard17/11/2014 at 10:04 #2031Robert [Tobii]ParticipantHi Gerard,
You can take a look at the EyeXMouse Github repository and see if it contains the example code you need to get started.
17/11/2014 at 15:06 #2045GerardParticipantThanks Robert,
Unfortunately the exe program from your link does not work at my place, since it requires a visual studio dll. Any alternatives?
Also, if someone has translated the c headers to Delphi/pascal import units to be able to use the eyex dll and is willing to share, that would be highly appreciated.
Kind regards,
Gerard26/05/2016 at 21:46 #5256YvonneParticipantHi everyone,
I actually tried translating the C headers to Delphi, but I failed miserably…
Nontheless, it is very well possible to control the EyeX in Delphi by using a facade DLL:- Make a copy of the C++ sample project that fits your requirement best. In my case I used MinimalGazeDataStream.
- Rename the copy of that project to something like “EyexFacade”.
- Open your EyexFacade project in the coding IDE of your choice (I used Visual Studio Express 2015) and configure the settings:
- Configuration / Output Type = Dynamic Link Library (DLL)
- Call Convention = _cdecl (important! Do NOT use stdcall!)
- Define the functions you need as dllexport and compile EyexFacade.dll
- Write your Delphi application and use EyexFacade.dll to control the EyeX
Here’s some sample code to get the gaze coordinates via callback:
========== EyexFacade ==========typedef void (TX_CALLCONVENTION *EC_OnGazeCallback)(int gazeX, int gazeY); // type definition of the callback function static EC_OnGazeCallback OnGazeCallback; // global variable pointing to the registered callback // the Delphi app calls this function to register a callback __declspec(dllexport) void SetOnGazeCallback(EC_OnGazeCallback callback) { OnGazeCallback = callback; } // this function should already be included in the sample project. void OnGazeDataEvent(TX_HANDLE hGazeDataBehavior) { TX_GAZEPOINTDATAEVENTPARAMS eventParams; if (txGetGazePointDataEventParams(hGazeDataBehavior, &eventParams) == TX_RESULT_OK) { OnGazeCallback((int)eventParams.X, (int)eventParams.Y); // call Delphi callback } }
========== Delphi application ==========
type TEyexOnGazeCallback = procedure(GazeX: Integer; GazeY: Integer); cdecl; PEyexOnGazeCallback = ^TEyexOnGazeCallback; TEyexSetCallback = procedure(callback: PEyexOnGazeCallback); cdecl; implementation procedure TForm1.FormCreate(Sender: TObject); var hDLL: THandle; hSetCallback: TEyexSetCallback; begin hDLL := LoadLibrary('EyexFacade.dll'); hSetCallback := GetProcAddress(hDLL, PAnsiChar(AnsiString('SetOnGazeCallback'))); hSetCallback(@OnGaze); end; procedure OnGaze(GazeX: Integer; GazeY: Integer); begin // do something usefull ;) end;
31/05/2016 at 09:55 #5264Grant [Tobii]KeymasterHi @kainasan,
Thank you very much for your tips, hopefully some users will find it useful!
05/09/2016 at 15:38 #5647Alan McNicolParticipantI’ve written a complete header file for delphi if anyone needs it. It’s only had limited testing but a conversion of the eye tracking C demo works perfectly.
15/09/2016 at 15:14 #5674GerardParticipantHi Alan,
That sounds great. Would it be possible for you to upload the header file for us to use?
Kind regards,
Gerard16/09/2016 at 10:38 #5675Alan McNicolParticipantThere are a couple of versions; one employs dynamic linking and the other static. The statically linked version is the more up to date and it is also complete in the sense that the comments have been converted to an xml style more friendly to the ‘code insight’ system I use. There are a couple of hard coded paths to the dll files in the eyeX.pas header file that would need to be adjusted or removed by any user.
When converting the functions to a delphi header variables passed as pointers always provide a design choice. One can pass it as a simple parameter with the ‘var’ declaration in delphi which means it is passed a pointer but this is transparent to the user, however, where a null pointer is allowed (as is often the case in the eyeX library) this cannot be done with a var parameter. In that case a pointer must be used instead. I think I’ve made sensible choices in each case but there are a lot of functions and a few may need to be altered. In addition where C structs have been converted to delphi records it is possible there may be errors if the byte alignment differs (easily fixed once identified). I suppose what I’m trying to say is that it is an early version and subject to revision.
I can upload the eye tracking test project as well if you wish. I haven’t written a delphi version of the c++ class yet but it looks trivial to implement.
The eyeX.pas header file is a little over 8500 lines long, and the eye tracking project is several files. Where would you like me to upload them? I could do it as inline code here but it would be a big post…
20/09/2016 at 09:19 #5681GerardParticipantHi Alan,
Thanks for the info.
I indeed do not see any possibility to upload files on this forum. Maybe use http://www.tinyupload.com/ and put the URL on this forum?
Kind regards,
Gerard20/09/2016 at 16:37 #5683Alan McNicolParticipantFiles are here.
The header file is called EyeX.pas All the other files are associated with the EyePositionSample project.
20/09/2016 at 17:33 #5684GerardParticipantGreat, thanks Alan!
28/09/2016 at 09:48 #5712Alan McNicolParticipantI’ve added a port of the activatable buttons sample. The executable should work if there is a copy of the eyeX dll in the folder or on the path (not the case in the first version I posted). I changed it a bit to enable tentative focus events, it seems to work better that way for me.
- AuthorPosts
- You must be logged in to reply to this topic.