Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed some issues with special keys combinations, added numpad keys. #640

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 18 additions & 6 deletions src/TestStack.White/InputDevices/Keyboard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,18 @@ public class Keyboard : IKeyboard
KeyboardInput.SpecialKeys.PAGEDOWN,
KeyboardInput.SpecialKeys.RIGHT,
KeyboardInput.SpecialKeys.LWIN,
KeyboardInput.SpecialKeys.RWIN
KeyboardInput.SpecialKeys.RWIN,

KeyboardInput.SpecialKeys.NUMPAD_0,
KeyboardInput.SpecialKeys.NUMPAD_1,
KeyboardInput.SpecialKeys.NUMPAD_2,
KeyboardInput.SpecialKeys.NUMPAD_3,
KeyboardInput.SpecialKeys.NUMPAD_4,
KeyboardInput.SpecialKeys.NUMPAD_5,
KeyboardInput.SpecialKeys.NUMPAD_6,
KeyboardInput.SpecialKeys.NUMPAD_7,
KeyboardInput.SpecialKeys.NUMPAD_8,
KeyboardInput.SpecialKeys.NUMPAD_9
};

[DllImport("user32", EntryPoint = "SendInput")]
Expand Down Expand Up @@ -151,21 +162,22 @@ private void SendKeyUp(short b, bool specialKey)
{
if (!keysHeld.Contains(b)) throw new InputDeviceException(string.Format("Cannot unpress the key {0}, it has not been pressed", b));
keysHeld.Remove(b);
KeyboardInput.KeyUpDown keyUpDown = GetSpecialKeyCode(specialKey, KeyboardInput.KeyUpDown.KEYEVENTF_KEYUP);
KeyboardInput.KeyUpDown keyUpDown = GetSpecialKeyCode(specialKey, KeyboardInput.KeyUpDown.KEYEVENTF_KEYUP, b);
SendInput(GetInputFor(b, keyUpDown));
}

private static KeyboardInput.KeyUpDown GetSpecialKeyCode(bool specialKey, KeyboardInput.KeyUpDown key)
private static KeyboardInput.KeyUpDown GetSpecialKeyCode(bool specialKey, KeyboardInput.KeyUpDown key, short b)
{
if (specialKey && scanCodeDependent.Contains((KeyboardInput.SpecialKeys) key)) key |= KeyboardInput.KeyUpDown.KEYEVENTF_EXTENDEDKEY;
if (specialKey && scanCodeDependent.Contains((KeyboardInput.SpecialKeys) b)) key |= KeyboardInput.KeyUpDown.KEYEVENTF_EXTENDEDKEY;
return key;
}

private void SendKeyDown(short b, bool specialKey)
{
if (keysHeld.Contains(b)) throw new InputDeviceException(string.Format("Cannot press the key {0} as its already pressed", b));
keysHeld.Add(b);
KeyboardInput.KeyUpDown keyUpDown = GetSpecialKeyCode(specialKey, KeyboardInput.KeyUpDown.KEYEVENTF_KEYDOWN);

KeyboardInput.KeyUpDown keyUpDown = GetSpecialKeyCode(specialKey, KeyboardInput.KeyUpDown.KEYEVENTF_KEYDOWN, b);
SendInput(GetInputFor(b, keyUpDown));
}

Expand Down Expand Up @@ -206,4 +218,4 @@ public virtual void LeaveAllKeys()
new List<KeyboardInput.SpecialKeys>(heldKeys).ForEach(LeaveKey);
}
}
}
}
17 changes: 16 additions & 1 deletion src/TestStack.White/WindowsAPI/WindowPlacement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,21 @@ public enum SpecialKeys
INSERT = 0x2D,
DELETE = 0x2E,
CAPS = 0x14,

NUMPAD_0 = 0x60,
NUMPAD_1 = 0x61,
NUMPAD_2 = 0x62,
NUMPAD_3 = 0x63,
NUMPAD_4 = 0x64,
NUMPAD_5 = 0x65,
NUMPAD_6 = 0x66,
NUMPAD_7 = 0x67,
NUMPAD_8 = 0x68,
NUMPAD_9 = 0x69,

VK_ADD = 0x6B,
VK_SUBTRACT = 0x6D,

F1 = 0x70,
F2 = 0x71,
F3 = 0x72,
Expand Down Expand Up @@ -204,4 +219,4 @@ public override string ToString()
return string.Format("R={0},G={1},B={2}", R, G, B);
}
}
}
}