Skip to content

Commit ad5534f

Browse files
committed
Changes naming of numlock and capslock states and transitions
1 parent 9a83915 commit ad5534f

File tree

4 files changed

+22
-18
lines changed

4 files changed

+22
-18
lines changed

InputStateManager/Inputs/Key.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,15 +117,15 @@ public bool Release(params Keys[] keys)
117117
public bool CtrlPress => OnePress(Keys.LeftControl, Keys.RightControl);
118118
public bool AltPress => OnePress(Keys.LeftAlt, Keys.RightAlt);
119119
public bool WindowsPress => OnePress(Keys.LeftWindows, Keys.RightWindows);
120-
public bool NumLockStatePress => State().NumLock && !OldState().NumLock;
121-
public bool CapsLockStatePress => State().CapsLock && !OldState().CapsLock;
120+
public bool NumLockStateEnter => State().NumLock && !OldState().NumLock;
121+
public bool CapsLockStateEnter => State().CapsLock && !OldState().CapsLock;
122122

123123
public bool ShiftRelease => Release(Keys.LeftShift, Keys.RightShift);
124124
public bool CtrlRelease => Release(Keys.LeftControl, Keys.RightControl);
125125
public bool AltRelease => Release(Keys.LeftAlt, Keys.RightAlt);
126126
public bool WindowsRelease => Release(Keys.LeftWindows, Keys.RightWindows);
127-
public bool NumLockStateRelease => !State().NumLock && OldState().NumLock;
128-
public bool CapsLockStateRelease => !State().CapsLock && OldState().CapsLock;
127+
public bool NumLockStateExit => !State().NumLock && OldState().NumLock;
128+
public bool CapsLockStateExit => !State().CapsLock && OldState().CapsLock;
129129
}
130130

131131
[PublicAPI]

NUnitTests/KeyTests.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -351,14 +351,14 @@ public void CapslockPressIsTriggeredAndReleased()
351351
.Returns(new KeyboardState(new Keys[] { }, true))
352352
.Returns(new KeyboardState());
353353
input.Update();
354-
Assert.IsTrue(input.Key.Is.CapsLockStatePress);
354+
Assert.IsTrue(input.Key.Is.CapsLockStateEnter);
355355
Assert.IsTrue(input.Key.Is.CapsLockStateOn);
356356
input.Update();
357-
Assert.IsFalse(input.Key.Is.CapsLockStatePress);
357+
Assert.IsFalse(input.Key.Is.CapsLockStateEnter);
358358
Assert.IsTrue(input.Key.Is.CapsLockStateOn);
359359
input.Update();
360-
Assert.IsFalse(input.Key.Is.CapsLockStatePress);
361-
Assert.IsTrue(input.Key.Is.CapsLockStateRelease);
360+
Assert.IsFalse(input.Key.Is.CapsLockStateEnter);
361+
Assert.IsTrue(input.Key.Is.CapsLockStateExit);
362362
Assert.IsTrue(input.Key.Is.CapsLockStateOff);
363363
}
364364

@@ -370,14 +370,14 @@ public void NumlockPressIsTriggeredAndReleased()
370370
.Returns(new KeyboardState(new Keys[] { }, false, true))
371371
.Returns(new KeyboardState());
372372
input.Update();
373-
Assert.IsTrue(input.Key.Is.NumLockStatePress);
373+
Assert.IsTrue(input.Key.Is.NumLockStateEnter);
374374
Assert.IsTrue(input.Key.Is.NumLockStateOn);
375375
input.Update();
376-
Assert.IsFalse(input.Key.Is.NumLockStatePress);
376+
Assert.IsFalse(input.Key.Is.NumLockStateEnter);
377377
Assert.IsTrue(input.Key.Is.NumLockStateOn);
378378
input.Update();
379-
Assert.IsFalse(input.Key.Is.NumLockStatePress);
380-
Assert.IsTrue(input.Key.Is.NumLockStateRelease);
379+
Assert.IsFalse(input.Key.Is.NumLockStateEnter);
380+
Assert.IsTrue(input.Key.Is.NumLockStateExit);
381381
Assert.IsTrue(input.Key.Is.NumLockStateOff);
382382
}
383383

README.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,12 @@ if (input.Key.Is.OnePress(new []{Keys.A, Keys.B})) {...}
110110
if (input.Key.Is.Down(Keys.A) && input.Key.Is.ShiftDown) {...}
111111
// Same for CTRL and ALT:
112112
if (input.Key.Is.CtrlRelease() || input.Key.Is.AltPress()) {...}
113-
// And NumLock and CapsLock:
114-
if (input.Key.Is.NumLockRelease() || input.Key.Is.CapsLockPress()) {..}
113+
// And NumLock- and CapsLock-states:
114+
if (input.Key.Is.NumLockOn() && input.Key.Is.CapsLockOff()) {..}
115+
// And the transitions of those states:
116+
if (input.Key.Is.NumLockStateExit() || input.Key.Is.CapsLockStateEnter()) {..}
117+
// Or their respective key-presses or up-down values:
118+
if (input.Key.Is.Down(Keys.NumLock) || input.Key.Is.Release(Keys.CapsLock))
115119
...
116120

117121

Test/Game1.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,10 +125,10 @@ private void DrawText()
125125
b.Append($"Keys NumLock Down: {input.Key.Is.Down(Keys.NumLock)} " +
126126
$"Pressed: {input.Key.Is.Press(Keys.NumLock)} " +
127127
$"Released: {input.Key.Is.Release(Keys.NumLock)}\n");
128-
b.Append($"bool NumLock on: {input.Key.Is.NumLockStateOn} / {input.Key.Is.NumLockStatePress}\n");
129-
b.Append($"bool NumLock off: {input.Key.Is.NumLockStateOff} / {input.Key.Is.NumLockStateRelease}\n");
130-
b.Append($"bool CapsLock on: {input.Key.Is.CapsLockStateOn} / {input.Key.Is.CapsLockStatePress}\n");
131-
b.Append($"bool CapsLock off: {input.Key.Is.CapsLockStateOff} / {input.Key.Is.CapsLockStateRelease}\n");
128+
b.Append($"bool NumLock on: {input.Key.Is.NumLockStateOn} / {input.Key.Is.NumLockStateEnter}\n");
129+
b.Append($"bool NumLock off: {input.Key.Is.NumLockStateOff} / {input.Key.Is.NumLockStateExit}\n");
130+
b.Append($"bool CapsLock on: {input.Key.Is.CapsLockStateOn} / {input.Key.Is.CapsLockStateEnter}\n");
131+
b.Append($"bool CapsLock off: {input.Key.Is.CapsLockStateOff} / {input.Key.Is.CapsLockStateExit}\n");
132132

133133
spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend);
134134
spriteBatch.DrawString(font, b, new Vector2(10, 10), Color.White);

0 commit comments

Comments
 (0)