Skip to content

Commit

Permalink
fixed IsConnectedAsync method
Browse files Browse the repository at this point in the history
  • Loading branch information
maximcus committed Jan 17, 2017
1 parent 6dcdd6a commit d8afa3a
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 17 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public enum HardwareKeyboardIgnoreOptions

/// <summary>
/// Ignore keyboard, if there is only one, and it's description
/// can be found in IgnoredDevices.
/// can be found in ListOfKeyboardsToIgnore.
/// </summary>
IgnoreIfSingleInstanceOnList,

Expand All @@ -44,9 +44,9 @@ public enum HardwareKeyboardIgnoreOptions

/// <summary>
/// Ignore all keyboards for which the description
/// can be found in IgnoredDevices
/// can be found in ListOfKeyboardsToIgnore
/// </summary>
IgnoreIfInstanceOnList,
IgnoreIfOnList,

/// <summary>
/// Ignore all keyboards
Expand All @@ -55,7 +55,7 @@ public enum HardwareKeyboardIgnoreOptions
}
```

If you want to ignore specific keyboard you should set `TabTipAutomation.IgnoreHardwareKeyboard` to either `IgnoreIfSingleInstanceOnList` or `IgnoreIfInstanceOnList`, and add keyboard description to `TabTipAutomation.IgnoredDevices`.
If you want to ignore specific keyboard you should set `TabTipAutomation.IgnoreHardwareKeyboard` to either `IgnoreIfSingleInstanceOnList` or `IgnoreIfOnList`, and add keyboard description to `TabTipAutomation.ListOfKeyboardsToIgnore`.

To get description of keyboards connected to machine you can use following code:

Expand Down
32 changes: 21 additions & 11 deletions WPFTabTip/HardwareKeyboard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public enum HardwareKeyboardIgnoreOptions

/// <summary>
/// Ignore keyboard, if there is only one, and it's description
/// can be found in IgnoredDevices.
/// can be found in ListOfKeyboardsToIgnore.
/// </summary>
IgnoreIfSingleInstanceOnList,

Expand All @@ -25,9 +25,9 @@ public enum HardwareKeyboardIgnoreOptions

/// <summary>
/// Ignore all keyboards for which the description
/// can be found in IgnoredDevices
/// can be found in ListOfKeyboardsToIgnore
/// </summary>
IgnoreIfInstanceOnList,
IgnoreIfOnList,

/// <summary>
/// Ignore all keyboards
Expand All @@ -51,18 +51,28 @@ internal static async Task<bool> IsConnectedAsync()
using (ManagementObjectSearcher Searcher = new ManagementObjectSearcher(SelectKeyboardsQuery))
using (ManagementObjectCollection Keyboards = Searcher.Get())
{
if (Keyboards.Count == 0)
return false;
switch (IgnoreOptions)
{
case HardwareKeyboardIgnoreOptions.IgnoreAll:
return false;
case HardwareKeyboardIgnoreOptions.DoNotIgnore:
return Keyboards.Count > 0;
case HardwareKeyboardIgnoreOptions.IgnoreIfSingleInstance:
return Keyboards.Count <= 1;
return Keyboards.Count > 1;
case HardwareKeyboardIgnoreOptions.IgnoreIfSingleInstanceOnList:
return Keyboards.Count <= 1 &&
!IsIgnoredKeyboard(Keyboards.Cast<ManagementBaseObject>().First());
case HardwareKeyboardIgnoreOptions.IgnoreIfInstanceOnList:
return Keyboards.Count == 0 ||
Keyboards.Cast<ManagementBaseObject>().All(k => IsIgnoredKeyboard(k));
return (Keyboards.Count > 1) ||
(Keyboards.Count == 1 &&
!IsIgnoredKeyboard(Keyboards.Cast<ManagementBaseObject>().First()));
case HardwareKeyboardIgnoreOptions.IgnoreIfOnList:
return Keyboards.Cast<ManagementBaseObject>().Any(k => !IsIgnoredKeyboard(k));
default:
return true;
}
Expand All @@ -87,7 +97,7 @@ private static bool IsIgnoredKeyboard(ManagementBaseObject keyboard)
.First()
.ToString();

return IgnoredDevices.Contains(description);
return ListOfKeyboardsToIgnore.Contains(description);
}

internal static HardwareKeyboardIgnoreOptions IgnoreOptions = HardwareKeyboardIgnoreOptions.DoNotIgnore;
Expand All @@ -96,6 +106,6 @@ private static bool IsIgnoredKeyboard(ManagementBaseObject keyboard)
/// Description of keyboards to ignore if there is only one instance of given keyboard.
/// If you want to ignore some ghost keyboard, add it's description to this list
/// </summary>
internal static List<string> IgnoredDevices { get; } = new List<string>();
internal static List<string> ListOfKeyboardsToIgnore { get; } = new List<string>();
}
}
4 changes: 2 additions & 2 deletions WPFTabTip/TabTipAutomation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,13 @@ public static HardwareKeyboardIgnoreOptions IgnoreHardwareKeyboard
/// Description of keyboards to ignore if there is only one instance of given keyboard.
/// If you want to ignore some ghost keyboard, add it's description to this list
/// </summary>
public static List<string> ListOfHardwareKeyboardsToIgnoreIfSingleInstance => HardwareKeyboard.IgnoredDevices;
public static List<string> ListOfHardwareKeyboardsToIgnoreIfSingleInstance => HardwareKeyboard.ListOfKeyboardsToIgnore;

/// <summary>
/// Description of keyboards to ignore.
/// If you want to ignore some ghost keyboard, add it's description to this list
/// </summary>
public static List<string> IgnoredDevices => HardwareKeyboard.IgnoredDevices;
public static List<string> ListOfKeyboardsToIgnore => HardwareKeyboard.ListOfKeyboardsToIgnore;

private static void AutomateTabTipClose(IObservable<Tuple<UIElement, bool>> focusObservable, Subject<bool> tabTipClosedSubject)
{
Expand Down

0 comments on commit d8afa3a

Please sign in to comment.