Scrolling on External Applications

Forum for C#/Windows development

Scrolling on External Applications

Postby Samleo » 24 Mar 2014, 10:45

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 :)
Samleo
 
Posts: 7
Joined: 01 Mar 2014, 11:30

Re: Scrolling on External Applications

Postby MastaLomaster » 30 Mar 2014, 12:55

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.
MastaLomaster
 
Posts: 37
Joined: 03 Mar 2014, 16:35

Re: Scrolling on External Applications

Postby MastaLomaster » 14 Apr 2014, 01:13

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};
MastaLomaster
 
Posts: 37
Joined: 03 Mar 2014, 16:35

Re: Scrolling on External Applications

Postby SimonH » 20 Aug 2014, 16:07

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.
SimonH
 
Posts: 4
Joined: 07 Aug 2014, 15:30


Return to C#