Skip to content

Commit

Permalink
Support showing ctrl, alt, win keys pressed down without any other key
Browse files Browse the repository at this point in the history
- Removed filtering of modifierkey to allow to handle them in ToInputs.
- Filtered triggering of modifier display for modifierkeys themselves in
ToInputs.
- Exposed IsModifierKeyPress as static to be used in KeyPress and
Messages.
- KeyPress.HasModifierPress returns false if key is a modifierkey itself
(allow the merging in Message).
- Message disable repeat counting incrementing for modifierkeys
themself, but still handling their repeat, in order for them to keep
showing while keydown.
  • Loading branch information
bfritscher committed Jul 14, 2017
1 parent 6f2ae82 commit ec1cd25
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
15 changes: 12 additions & 3 deletions src/Carnac.Logic/KeyProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class KeyProvider : IKeyProvider
readonly IPasswordModeService passwordModeService;
readonly IDesktopLockEventService desktopLockEventService;

private readonly IList<Keys> modifierKeys =
private static readonly IList<Keys> modifierKeys =
new List<Keys>
{
Keys.LControlKey,
Expand Down Expand Up @@ -68,7 +68,7 @@ public IObservable<KeyPress> GetKeyStream()

var keyStreamSubsription = interceptKeysSource.GetKeyStream()
.Select(DetectWindowsKey)
.Where(k => !IsModifierKeyPress(k) && k.KeyDirection == KeyDirection.Down)
.Where(k => k.KeyDirection == KeyDirection.Down)
.Select(ToCarnacKeyPress)
.Where(keypress => keypress != null)
.Where(k => !passwordModeService.CheckPasswordMode(k.InterceptKeyEventArgs))
Expand All @@ -91,7 +91,7 @@ InterceptKeyEventArgs DetectWindowsKey(InterceptKeyEventArgs interceptKeyEventAr
return interceptKeyEventArgs;
}

bool IsModifierKeyPress(InterceptKeyEventArgs interceptKeyEventArgs)
public static bool IsModifierKeyPress(InterceptKeyEventArgs interceptKeyEventArgs)
{
return modifierKeys.Contains(interceptKeyEventArgs.Key);
}
Expand Down Expand Up @@ -123,6 +123,15 @@ static IEnumerable<string> ToInputs(bool isLetter, bool isWinKeyPressed, Interce
var controlPressed = interceptKeyEventArgs.ControlPressed;
var altPressed = interceptKeyEventArgs.AltPressed;
var shiftPressed = interceptKeyEventArgs.ShiftPressed;

if (IsModifierKeyPress(interceptKeyEventArgs))
{
controlPressed = false;
altPressed = false;
shiftPressed = false;
isWinKeyPressed = false;
}

if (controlPressed)
yield return "Ctrl";
if (altPressed)
Expand Down
4 changes: 2 additions & 2 deletions src/Carnac.Logic/Models/KeyPress.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ public bool HasModifierPressed
{
get
{
return InterceptKeyEventArgs.AltPressed
return !KeyProvider.IsModifierKeyPress(InterceptKeyEventArgs) && (InterceptKeyEventArgs.AltPressed
|| InterceptKeyEventArgs.ControlPressed
|| WinkeyPressed;
|| WinkeyPressed);
}
}

Expand Down
7 changes: 6 additions & 1 deletion src/Carnac.Logic/Models/Message.cs
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ private sealed class RepeatedKeyPress
readonly bool requiresPrefix;
readonly bool nextRequiresSeperator;
readonly string[] textParts;
readonly bool isRepeatable;
int repeatCount;

public RepeatedKeyPress(KeyPress keyPress, bool requiresPrefix = false)
Expand All @@ -168,13 +169,17 @@ public RepeatedKeyPress(KeyPress keyPress, bool requiresPrefix = false)
textParts = keyPress.GetTextParts().ToArray();
this.requiresPrefix = requiresPrefix;
repeatCount = 1;
isRepeatable = !KeyProvider.IsModifierKeyPress(keyPress.InterceptKeyEventArgs);
}

public bool NextRequiresSeperator { get { return nextRequiresSeperator; } }

public void IncrementRepeat()
{
repeatCount++;
if (isRepeatable)
{
repeatCount++;
}
}

public bool IsRepeatedBy(KeyPress nextKeyPress)
Expand Down

0 comments on commit ec1cd25

Please sign in to comment.