Skip to content

Commit 4c1fdf0

Browse files
author
Jake Ginnivan
committed
Merge pull request #133 from JakeGinnivan/ImproveMouseButtonSwap
Detect swapped mouse buttons rather than being a configuration option
2 parents fe147fd + 630f5f5 commit 4c1fdf0

File tree

6 files changed

+33
-26
lines changed

6 files changed

+33
-26
lines changed

src/TestStack.White.sln.DotSettings

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/ALIGN_MULTILINE_EXPRESSION/@EntryValue">False</s:Boolean>
66
<s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/ANONYMOUS_METHOD_DECLARATION_BRACES/@EntryValue">NEXT_LINE</s:String>
77
<s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/CASE_BLOCK_BRACES/@EntryValue">NEXT_LINE</s:String>
8+
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/EXPLICIT_INTERNAL_MODIFIER/@EntryValue">False</s:Boolean>
89
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/EXPLICIT_PRIVATE_MODIFIER/@EntryValue">False</s:Boolean>
910
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/INDENT_ANONYMOUS_METHOD_BLOCK/@EntryValue">False</s:Boolean>
1011
<s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/INITIALIZER_BRACES/@EntryValue">NEXT_LINE</s:String>

src/TestStack.White/Configuration/CoreAppXmlConfiguration.cs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -138,12 +138,6 @@ public virtual bool MoveMouseToGetStatusOfHourGlass
138138
set { SetUsedValue("MoveMouseToGetStatusOfHourGlass", value); }
139139
}
140140

141-
public virtual bool InvertMouseButtons
142-
{
143-
get { return Convert.ToBoolean(UsedValues["InvertMouseButtons"]); }
144-
set { SetUsedValue("InvertMouseButtons", value); }
145-
}
146-
147141
public virtual ILoggerFactory LoggerFactory { get; set; }
148142

149143
public virtual IDisposable ApplyTemporarySetting(Action<ICoreConfiguration> changes)

src/TestStack.White/Configuration/CoreConfiguration.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ public interface ICoreConfiguration
3232
bool RawElementBasedSearch { get; set; }
3333
int DoubleClickInterval { get; set; }
3434
bool MoveMouseToGetStatusOfHourGlass { get; set; }
35-
bool InvertMouseButtons { get; set; }
3635
ILoggerFactory LoggerFactory { get; set; }
3736
IDisposable ApplyTemporarySetting(Action<ICoreConfiguration> changes);
3837
}

src/TestStack.White/InputDevices/Mouse.cs

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,36 +15,37 @@ namespace TestStack.White.InputDevices
1515
public class Mouse : IMouse
1616
{
1717
[DllImport("user32", EntryPoint = "SendInput")]
18-
private static extern int SendInput(uint numberOfInputs, ref Input input, int structSize);
18+
static extern int SendInput(uint numberOfInputs, ref Input input, int structSize);
1919

2020
[DllImport("user32", EntryPoint = "SendInput")]
21-
private static extern int SendInput64(int numberOfInputs, ref Input64 input, int structSize);
22-
21+
static extern int SendInput64(int numberOfInputs, ref Input64 input, int structSize);
22+
2323
[DllImport("user32.dll")]
24-
private static extern IntPtr GetMessageExtraInfo();
24+
static extern IntPtr GetMessageExtraInfo();
2525

2626
[DllImport("user32.dll")]
2727

28-
private static extern bool GetCursorPos(ref System.Drawing.Point cursorInfo);
28+
static extern bool GetCursorPos(ref System.Drawing.Point cursorInfo);
29+
30+
[DllImport("user32.dll")]
31+
static extern bool SetCursorPos(int x, int y);
2932

3033
[DllImport("user32.dll")]
31-
private static extern bool SetCursorPos(int x, int y);
34+
static extern bool GetCursorInfo(ref CursorInfo cursorInfo);
3235

3336
[DllImport("user32.dll")]
34-
private static extern bool GetCursorInfo(ref CursorInfo cursorInfo);
37+
static extern short GetDoubleClickTime();
3538

3639
[DllImport("user32.dll")]
37-
private static extern short GetDoubleClickTime();
40+
static extern int GetSystemMetrics(SystemMetric smIndex);
3841

3942
public static Mouse Instance = new Mouse();
40-
private DateTime lastClickTime = DateTime.Now;
41-
private readonly short doubleClickTime = GetDoubleClickTime();
42-
private Point lastClickLocation;
43-
private const int ExtraMillisecondsBecauseOfBugInWindows = 13;
43+
DateTime lastClickTime = DateTime.Now;
44+
readonly short doubleClickTime = GetDoubleClickTime();
45+
Point lastClickLocation;
46+
const int ExtraMillisecondsBecauseOfBugInWindows = 13;
4447

45-
private Mouse()
46-
{
47-
}
48+
Mouse() { }
4849

4950
public virtual Point Location
5051
{
@@ -77,22 +78,22 @@ public virtual MouseCursor Cursor
7778

7879
private static int RightMouseButtonDown
7980
{
80-
get { return (CoreAppXmlConfiguration.Instance.InvertMouseButtons ? WindowsConstants.MOUSEEVENTF_RIGHTDOWN : WindowsConstants.MOUSEEVENTF_LEFTDOWN); }
81+
get { return GetSystemMetrics(SystemMetric.SM_SWAPBUTTON) == 0 ? WindowsConstants.MOUSEEVENTF_RIGHTDOWN : WindowsConstants.MOUSEEVENTF_LEFTDOWN; }
8182
}
8283

8384
private static int RightMouseButtonUp
8485
{
85-
get { return (CoreAppXmlConfiguration.Instance.InvertMouseButtons ? WindowsConstants.MOUSEEVENTF_RIGHTUP : WindowsConstants.MOUSEEVENTF_LEFTUP); }
86+
get { return GetSystemMetrics(SystemMetric.SM_SWAPBUTTON) == 0 ? WindowsConstants.MOUSEEVENTF_RIGHTUP : WindowsConstants.MOUSEEVENTF_LEFTUP; }
8687
}
8788

8889
private static int LeftMouseButtonDown
8990
{
90-
get { return (CoreAppXmlConfiguration.Instance.InvertMouseButtons ? WindowsConstants.MOUSEEVENTF_LEFTDOWN : WindowsConstants.MOUSEEVENTF_RIGHTDOWN); }
91+
get { return GetSystemMetrics(SystemMetric.SM_SWAPBUTTON) == 0 ? WindowsConstants.MOUSEEVENTF_LEFTDOWN : WindowsConstants.MOUSEEVENTF_RIGHTDOWN; }
9192
}
9293

9394
private static int LeftMouseButtonUp
9495
{
95-
get { return (CoreAppXmlConfiguration.Instance.InvertMouseButtons ? WindowsConstants.MOUSEEVENTF_LEFTUP : WindowsConstants.MOUSEEVENTF_RIGHTUP); }
96+
get { return GetSystemMetrics(SystemMetric.SM_SWAPBUTTON) == 0 ? WindowsConstants.MOUSEEVENTF_LEFTUP : WindowsConstants.MOUSEEVENTF_RIGHTUP; }
9697
}
9798

9899
public virtual void RightClick()
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
namespace TestStack.White.InputDevices
2+
{
3+
// ReSharper disable InconsistentNaming
4+
public enum SystemMetric
5+
{
6+
/// <summary>
7+
/// Nonzero if the meanings of the left and right mouse buttons are swapped; otherwise, 0.
8+
/// </summary>
9+
SM_SWAPBUTTON = 23
10+
}
11+
}

src/TestStack.White/TestStack.White.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@
9393
<Compile Include="Configuration\WhiteDefaultLogger.cs" />
9494
<Compile Include="Configuration\WhiteDefaultLoggerFactory.cs" />
9595
<Compile Include="InputDevices\Input64.cs" />
96+
<Compile Include="InputDevices\SystemMetric.cs" />
9697
<Compile Include="Interceptors\IWhiteInterceptor.cs" />
9798
<Compile Include="Properties\AssemblyInfo.cs" />
9899
<Compile Include="AutomationElementSearch\AutomationElementFinder.cs" />

0 commit comments

Comments
 (0)