Home Forums Software Development using dll in Delphi, control the mouse

Viewing 12 posts - 1 through 12 (of 12 total)
  • Author
    Posts
  • #2014
    Gerard
    Participant

    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,
    Gerard

    #2031
    Robert [Tobii]
    Participant

    Hi Gerard,

    You can take a look at the EyeXMouse Github repository and see if it contains the example code you need to get started.

    #2045
    Gerard
    Participant

    Thanks 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,
    Gerard

    #5256
    Yvonne
    Participant

    Hi 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:

    1. Make a copy of the C++ sample project that fits your requirement best. In my case I used MinimalGazeDataStream.
    2. Rename the copy of that project to something like “EyexFacade”.
    3. 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!)
    4. Define the functions you need as dllexport and compile EyexFacade.dll
    5. 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;
    #5264
    Grant [Tobii]
    Keymaster

    Hi @kainasan,

    Thank you very much for your tips, hopefully some users will find it useful!

    #5647
    Alan McNicol
    Participant

    I’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.

    #5674
    Gerard
    Participant

    Hi Alan,
    That sounds great. Would it be possible for you to upload the header file for us to use?
    Kind regards,
    Gerard

    #5675
    Alan McNicol
    Participant

    There 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…

    #5681
    Gerard
    Participant

    Hi 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,
    Gerard

    #5683
    Alan McNicol
    Participant

    Files are here.

    The header file is called EyeX.pas All the other files are associated with the EyePositionSample project.

    #5684
    Gerard
    Participant

    Great, thanks Alan!

    #5712
    Alan McNicol
    Participant

    I’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.

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