Skip to content

Commit

Permalink
Detect swapped mouse buttons rather than being a configuration option
Browse files Browse the repository at this point in the history
  • Loading branch information
Jake Ginnivan committed Jul 29, 2013
1 parent fe147fd commit 630f5f5
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 26 deletions.
1 change: 1 addition & 0 deletions src/TestStack.White.sln.DotSettings
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/ALIGN_MULTILINE_EXPRESSION/@EntryValue">False</s:Boolean>
<s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/ANONYMOUS_METHOD_DECLARATION_BRACES/@EntryValue">NEXT_LINE</s:String>
<s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/CASE_BLOCK_BRACES/@EntryValue">NEXT_LINE</s:String>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/EXPLICIT_INTERNAL_MODIFIER/@EntryValue">False</s:Boolean>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/EXPLICIT_PRIVATE_MODIFIER/@EntryValue">False</s:Boolean>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/INDENT_ANONYMOUS_METHOD_BLOCK/@EntryValue">False</s:Boolean>
<s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/INITIALIZER_BRACES/@EntryValue">NEXT_LINE</s:String>
Expand Down
6 changes: 0 additions & 6 deletions src/TestStack.White/Configuration/CoreAppXmlConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -138,12 +138,6 @@ public virtual bool MoveMouseToGetStatusOfHourGlass
set { SetUsedValue("MoveMouseToGetStatusOfHourGlass", value); }
}

public virtual bool InvertMouseButtons
{
get { return Convert.ToBoolean(UsedValues["InvertMouseButtons"]); }
set { SetUsedValue("InvertMouseButtons", value); }
}

public virtual ILoggerFactory LoggerFactory { get; set; }

public virtual IDisposable ApplyTemporarySetting(Action<ICoreConfiguration> changes)
Expand Down
1 change: 0 additions & 1 deletion src/TestStack.White/Configuration/CoreConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ public interface ICoreConfiguration
bool RawElementBasedSearch { get; set; }
int DoubleClickInterval { get; set; }
bool MoveMouseToGetStatusOfHourGlass { get; set; }
bool InvertMouseButtons { get; set; }
ILoggerFactory LoggerFactory { get; set; }
IDisposable ApplyTemporarySetting(Action<ICoreConfiguration> changes);
}
Expand Down
39 changes: 20 additions & 19 deletions src/TestStack.White/InputDevices/Mouse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,36 +15,37 @@ namespace TestStack.White.InputDevices
public class Mouse : IMouse
{
[DllImport("user32", EntryPoint = "SendInput")]
private static extern int SendInput(uint numberOfInputs, ref Input input, int structSize);
static extern int SendInput(uint numberOfInputs, ref Input input, int structSize);

[DllImport("user32", EntryPoint = "SendInput")]
private static extern int SendInput64(int numberOfInputs, ref Input64 input, int structSize);
static extern int SendInput64(int numberOfInputs, ref Input64 input, int structSize);

[DllImport("user32.dll")]
private static extern IntPtr GetMessageExtraInfo();
static extern IntPtr GetMessageExtraInfo();

[DllImport("user32.dll")]

private static extern bool GetCursorPos(ref System.Drawing.Point cursorInfo);
static extern bool GetCursorPos(ref System.Drawing.Point cursorInfo);

[DllImport("user32.dll")]
static extern bool SetCursorPos(int x, int y);

[DllImport("user32.dll")]
private static extern bool SetCursorPos(int x, int y);
static extern bool GetCursorInfo(ref CursorInfo cursorInfo);

[DllImport("user32.dll")]
private static extern bool GetCursorInfo(ref CursorInfo cursorInfo);
static extern short GetDoubleClickTime();

[DllImport("user32.dll")]
private static extern short GetDoubleClickTime();
static extern int GetSystemMetrics(SystemMetric smIndex);

public static Mouse Instance = new Mouse();
private DateTime lastClickTime = DateTime.Now;
private readonly short doubleClickTime = GetDoubleClickTime();
private Point lastClickLocation;
private const int ExtraMillisecondsBecauseOfBugInWindows = 13;
DateTime lastClickTime = DateTime.Now;
readonly short doubleClickTime = GetDoubleClickTime();
Point lastClickLocation;
const int ExtraMillisecondsBecauseOfBugInWindows = 13;

private Mouse()
{
}
Mouse() { }

public virtual Point Location
{
Expand Down Expand Up @@ -77,22 +78,22 @@ public virtual MouseCursor Cursor

private static int RightMouseButtonDown
{
get { return (CoreAppXmlConfiguration.Instance.InvertMouseButtons ? WindowsConstants.MOUSEEVENTF_RIGHTDOWN : WindowsConstants.MOUSEEVENTF_LEFTDOWN); }
get { return GetSystemMetrics(SystemMetric.SM_SWAPBUTTON) == 0 ? WindowsConstants.MOUSEEVENTF_RIGHTDOWN : WindowsConstants.MOUSEEVENTF_LEFTDOWN; }
}

private static int RightMouseButtonUp
{
get { return (CoreAppXmlConfiguration.Instance.InvertMouseButtons ? WindowsConstants.MOUSEEVENTF_RIGHTUP : WindowsConstants.MOUSEEVENTF_LEFTUP); }
get { return GetSystemMetrics(SystemMetric.SM_SWAPBUTTON) == 0 ? WindowsConstants.MOUSEEVENTF_RIGHTUP : WindowsConstants.MOUSEEVENTF_LEFTUP; }
}

private static int LeftMouseButtonDown
{
get { return (CoreAppXmlConfiguration.Instance.InvertMouseButtons ? WindowsConstants.MOUSEEVENTF_LEFTDOWN : WindowsConstants.MOUSEEVENTF_RIGHTDOWN); }
get { return GetSystemMetrics(SystemMetric.SM_SWAPBUTTON) == 0 ? WindowsConstants.MOUSEEVENTF_LEFTDOWN : WindowsConstants.MOUSEEVENTF_RIGHTDOWN; }
}

private static int LeftMouseButtonUp
{
get { return (CoreAppXmlConfiguration.Instance.InvertMouseButtons ? WindowsConstants.MOUSEEVENTF_LEFTUP : WindowsConstants.MOUSEEVENTF_RIGHTUP); }
get { return GetSystemMetrics(SystemMetric.SM_SWAPBUTTON) == 0 ? WindowsConstants.MOUSEEVENTF_LEFTUP : WindowsConstants.MOUSEEVENTF_RIGHTUP; }
}

public virtual void RightClick()
Expand Down
11 changes: 11 additions & 0 deletions src/TestStack.White/InputDevices/SystemMetric.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
namespace TestStack.White.InputDevices
{
// ReSharper disable InconsistentNaming
public enum SystemMetric
{
/// <summary>
/// Nonzero if the meanings of the left and right mouse buttons are swapped; otherwise, 0.
/// </summary>
SM_SWAPBUTTON = 23
}
}
1 change: 1 addition & 0 deletions src/TestStack.White/TestStack.White.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@
<Compile Include="Configuration\WhiteDefaultLogger.cs" />
<Compile Include="Configuration\WhiteDefaultLoggerFactory.cs" />
<Compile Include="InputDevices\Input64.cs" />
<Compile Include="InputDevices\SystemMetric.cs" />
<Compile Include="Interceptors\IWhiteInterceptor.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="AutomationElementSearch\AutomationElementFinder.cs" />
Expand Down

0 comments on commit 630f5f5

Please sign in to comment.