I want to detect the scrolling direction of another application. I am able to do so if the user scrolls through Mouse Wheel or Keyboard (Up/Down/Left/Right keys) through hooks. But I am not able to capture the same when the user uses the scrollbars present on the applications like Chrome.
I've tried below native method, but it does not work for many applications like chrome and works for Notepad++, as it is not able to detect scroll bars for chrome. I want something that works for all the applications.
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool GetScrollInfo(IntPtr hwnd, int fnBar, ref SCROLLINFO lpsi);
I have quite a bit of research but could not find anything that could give me the directions in which the page is scrolling. Please let me know if any further information is required.
Update:
I am trying to use UI Automation to get the scroll bar information for Chrome.
Here's how?
I have made a collection of windows Gui Rectangles using EnumChildWindows
, which retrieved child controls as well. Based upon the mouse position, have selected the window handle whose Gui Rectangle contains my mouse position. The handle I obtained had the Gui Rectangle = chrome's client area.
Problem:
Below is the code. And it gives me an empty collection in elementCollection
in case of Chrome and successfully returns 2 scroll bar elements in case of Notepad++.
var element = AutomationElement.FromHandle(handle);
if(element != null)
{
Condition condition =
new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.ScrollBar);
// Find all children that match the specified conditions.
AutomationElementCollection elementCollection =
element.FindAll(TreeScope.SubTree, condition);
}