For Portable Natural User Interface Development (PNUI) we implemented a python version of the OpenCV code here to control your computer mouse using your eye.
OpenCV has built in haarcascades for face and eye detection, however none for pupil detection, which we use to control the mouse (using the windows api library for python).
Following the algorithm used by TangoWithCode, we instead use OpenCV's circle detection within the already detected eye area, and select the circle with the darkest overall color as the pupil, since your pupil is entirely black.
Once you have the location of the pupil, you can calculate how far from the center of the eye it is and move the mouse accordingly, treating the pupil like a joystick.
Source: here