Page 1 of 1

Scrolling on External Applications

PostPosted: 24 Mar 2014, 10:45
by Samleo
Hi, I am wondering how to allow scrolling to work with external applications (not self-coded) such as Google Chrome. I want to create an app that allows for the user to integrate Eye-tracking into everyday computer use.

I already have an application working in the background to control the mouse cursor, and now I want to allow for the user to look at the bottom/top part of the screen and scroll. Is there a way to do that with the available SDK? (I have checked out the Scroll SDK - the one with NYTimes, but I want it to work on external applications)

Any help is appreciated :)

Re: Scrolling on External Applications

PostPosted: 30 Mar 2014, 12:55
by MastaLomaster
I use the code below. It utilizes SendInput win32 function.
timelag is in microseconds. If you use time in milliseconds, amend the code (divide all the constants by 1000).
This is pure C, but in C# it should look familiar.
Code: Select all
void Scroll(uint64_t timelag, int direction)
{
   if(timelag>100000UL) timelag=100000UL;

   INPUT input;

   input.type=INPUT_MOUSE;
   input.mi.dx=0L;
   input.mi.dy=0L;
   input.mi.mouseData=direction*(timelag/2000UL);
   input.mi.dwFlags=MOUSEEVENTF_WHEEL;
   input.mi.time=0;
   input.mi.dwExtraInfo=0;

   SendInput(1,&input,sizeof(INPUT));
}

important note: some modern applications require mouse cursor to be located INSIDE the scrollable window (Internet Explorer, for examples). Legacy applications and some simple applications (like notepad.exe) don't care of the mouse cursor position.

Re: Scrolling on External Applications

PostPosted: 14 Apr 2014, 01:13
by MastaLomaster
Amendment:

You must initialize the INPUT structure with zeros, otherwise it may cause unpredictable mouse behavior.
So, instead of
Code: Select all
INPUT input;


You need
Code: Select all
INPUT input={0};

Re: Scrolling on External Applications

PostPosted: 20 Aug 2014, 16:07
by SimonH
this looks interesting, i will try this tomorrow. right now iam using a combination of getting the Desktop resolution and the mouse_event in dependance of what part on the window you are looking: (currently working with c++)

int const SCROLLUP = 120;
int const SCROLLDOWN = -120;

void GetDesktopResolution(int& horizontal, int& vertical)
{
RECT desktop;
// Get a handle to the desktop window
const HWND hDesktop = GetDesktopWindow();
// Get the size of screen to the variable desktop
GetWindowRect(hDesktop, &desktop);
// The top left corner will have coordinates (0,0)
// and the bottom right corner will have coordinates
// (horizontal, vertical)
horizontal = desktop.right;
vertical = desktop.bottom;
}

mouse_event(MOUSEEVENTF_WHEEL, 0, 0, SCROLLUP);
mouse_event(MOUSEEVENTF_WHEEL, 0, 0, SCROLLDOWN);

Its easy to integrate. The only thing that bother me is that it isnt really smooth. Either you have full scroll or zero scroll. Maybe your solution works better.