From 1b092074b21379df6d2c0af607838d6f97bb9d6f Mon Sep 17 00:00:00 2001 From: Nina Date: Mon, 25 Mar 2019 12:07:02 +0100 Subject: [PATCH] Fixed some issues with special keys combinations, added numpad keys. --- src/TestStack.White/InputDevices/Keyboard.cs | 24 ++++++++++++++----- .../WindowsAPI/WindowPlacement.cs | 17 ++++++++++++- 2 files changed, 34 insertions(+), 7 deletions(-) diff --git a/src/TestStack.White/InputDevices/Keyboard.cs b/src/TestStack.White/InputDevices/Keyboard.cs index f366eabe..8bcd1f55 100644 --- a/src/TestStack.White/InputDevices/Keyboard.cs +++ b/src/TestStack.White/InputDevices/Keyboard.cs @@ -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")] @@ -151,13 +162,13 @@ 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; } @@ -165,7 +176,8 @@ 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)); } @@ -206,4 +218,4 @@ public virtual void LeaveAllKeys() new List(heldKeys).ForEach(LeaveKey); } } -} \ No newline at end of file +} diff --git a/src/TestStack.White/WindowsAPI/WindowPlacement.cs b/src/TestStack.White/WindowsAPI/WindowPlacement.cs index 7682e162..b7178361 100644 --- a/src/TestStack.White/WindowsAPI/WindowPlacement.cs +++ b/src/TestStack.White/WindowsAPI/WindowPlacement.cs @@ -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, @@ -204,4 +219,4 @@ public override string ToString() return string.Format("R={0},G={1},B={2}", R, G, B); } } -} \ No newline at end of file +}