public static void SendThreeKeys(System.Windows.Input.Key key1, System.Windows.Input.Key key2, System.Windows.Input.Key key3, string msg, int sleepTime) { Thread.Sleep(sleepTime); Library.ValidateArgumentNonNull(msg, "SendSingleKey() msg argument is null"); if (msg.Length > 0) { msg = msg + " by "; } /* changing to new flexible logging */ //Logger.LogComment(msg + "Sending keys " + key1.ToString() + ", " + key2.ToString() + " + " + key3.ToString()); UIVerifyLogger.LogComment(msg + "Sending keys " + key1.ToString() + ", " + key2.ToString() + " + " + key3.ToString()); ATGTestInput.Input.SendKeyboardInput(key1, true); Thread.Sleep(300); ATGTestInput.Input.SendKeyboardInput(key2, true); Thread.Sleep(300); ATGTestInput.Input.SendKeyboardInput(key3, true); Thread.Sleep(sleepTime); ATGTestInput.Input.SendKeyboardInput(key3, false); ATGTestInput.Input.SendKeyboardInput(key1, false); ATGTestInput.Input.SendKeyboardInput(key2, false); Thread.Sleep(sleepTime); }
static public WindowsInput.Native.VirtualKeyCode?WindowsInputVirtualKeyCodeBerecneAusSystemWindowsInputKey( System.Windows.Input.Key WindowsInputKey) { if (System.Windows.Input.Key.F1 <= WindowsInputKey && WindowsInputKey <= System.Windows.Input.Key.F24) { return((WindowsInput.Native.VirtualKeyCode)(((int)WindowsInputKey - (int)System.Windows.Input.Key.F1) + (int)WindowsInput.Native.VirtualKeyCode.F1)); } if (System.Windows.Input.Key.D0 <= WindowsInputKey && WindowsInputKey <= System.Windows.Input.Key.D9) { return((WindowsInput.Native.VirtualKeyCode)(((int)WindowsInputKey - (int)System.Windows.Input.Key.D0) + (int)WindowsInput.Native.VirtualKeyCode.VK_0)); } var WindowsInputKeySictString = WindowsInputKey.ToString(); WindowsInput.Native.VirtualKeyCode Result; if (Enum.TryParse(WindowsInputKeySictString, false, out Result)) { return(Result); } if (Enum.TryParse(WindowsInputKeySictString, true, out Result)) { return(Result); } return(null); }
public void AssignKeyAction(string key, System.Windows.Input.Key value) { Key keys; Enum.TryParse(value.ToString(), out keys); controlSettings.KeyboardAssignment[key] = keys; }
/// <summary> /// 通过KEY返回值 /// </summary> /// <param name="key"></param> /// <returns></returns> internal string GetStrFromKey(System.Windows.Input.Key key) { if (key >= System.Windows.Input.Key.D0 && key <= System.Windows.Input.Key.D9) { return(key.ToString().TrimStart("D")); } else if (key >= System.Windows.Input.Key.NumPad0 && key <= System.Windows.Input.Key.NumPad9) { return(key.ToString().TrimStart("NumPad")); } else if (key == System.Windows.Input.Key.OemPeriod || key == System.Windows.Input.Key.Decimal) { return("."); } return(key.ToString()); }
public static Key FromSystemKey(System.Windows.Input.Key SystemKey) { if (Enum.TryParse(SystemKey.ToString(), out Key DirectKey)) { return(DirectKey); } Debug.WriteLine($"Warning; SystemKey '{SystemKey}' does not have a direct {nameof(Key)} conversion."); return((Key)SystemKey); }
/* * This method performs the lookup and returns the VirtualKeyCode if it is found. * If it is not found, a 0 is returned. */ public static WindowsInput.VirtualKeyCode LookupVKey(System.Windows.Input.Key enumKey) { // Since vKey cannot be null, use 0 to represent an invalid key WindowsInput.VirtualKeyCode vKey = 0; try { lookup.TryGetValue(enumKey, out vKey); } catch (ArgumentException) { Console.WriteLine("Invalid key" + enumKey.ToString()); } return(vKey); }
public static void SendOneKey(System.Windows.Input.Key key, string msg, int sleepTime) { Thread.Sleep(sleepTime); Library.ValidateArgumentNonNull(msg, "msg argument cannot be null"); if (msg.Length > 0) { msg = msg + " by "; } /* changing to new flexible logging */ //Logger.LogComment(msg + "Sending key " + key.ToString()); UIVerifyLogger.LogComment(msg + "Sending key " + key.ToString()); ATGTestInput.Input.SendKeyboardInput(key, true); ATGTestInput.Input.SendKeyboardInput(key, false); }
} //class KeyboardRowDescriptor internal KeyboardLayout(MainWindow parent) { this.parent = parent; this.sampleRenderer = new SampleRenderer(parent); KeyboardElementList keyList = new KeyboardElementList(0); Rows = new KeyboardRowDescriptor[DefinitionSet.keyboardHeight]; for (int yIndex = 0; yIndex < DefinitionSet.keyboardHeight; ++yIndex) { bool shortRow = yIndex % 2 == 0; int xLength = DefinitionSet.maximimKeyboardWidth; if (!shortRow) { ++xLength; } KeyboardElement[] rowElements = new KeyboardElement[xLength]; for (int xIndex = 0; xIndex < xLength; ++xIndex) { var ke = new KeyboardElement(parent, (byte)yIndex, (byte)xIndex, sampleRenderer.Recording); keyList.Add(ke); rowElements[xIndex] = ke; } //loop x Rows[yIndex] = new KeyboardRowDescriptor(rowElements, shortRow); } //loop y int physicalRightmost = int.MinValue; for (int yIndex = 0; yIndex < Main.PhysicalKeyboardLayout.physicalRows.Length; ++yIndex) { int rightMost = Main.PhysicalKeyboardLayout.physicalRows[yIndex].Length * 2 - yIndex; if (physicalRightmost < rightMost) { physicalRightmost = rightMost; } } //loop physicalRightmost += 1; int rowShift = 1 + (DefinitionSet.keyboardHeight - Main.PhysicalKeyboardLayout.physicalRows.Length) / 2; int shiftInRow = 1 + (DefinitionSet.maximimKeyboardWidth * 2 - physicalRightmost) / 4; this.Keys = keyList.ToArray(); int maxKey = -1; for (int yIndex = 0; yIndex < Main.PhysicalKeyboardLayout.physicalRows.Length; ++yIndex) { for (int xIndex = 0; xIndex < Main.PhysicalKeyboardLayout.physicalRows[yIndex].Length; ++xIndex) { int actualIndexX = shiftInRow; KeyboardElement element = Rows[yIndex + rowShift].Elements[actualIndexX - yIndex + xIndex]; Key key = Main.PhysicalKeyboardLayout.physicalRows[yIndex][xIndex]; string sKey = key.ToString(); if (sKey.Length > 1) { if (key < Key.D0 || key > Key.D9) { char replacement; if (DefinitionSet.keyReplacements.TryGetValue(key, out replacement)) { sKey = new string(new char[] { replacement }); } } else { sKey = sKey.Substring(1, 1); } } //if element.Character = sKey; if ((int)key > maxKey) { maxKey = (int)key; } notes.Add(key, element); } // loop x if (Rows[yIndex].IsShort) { ++shiftInRow; } } //loop y MaxKey = (Key)maxKey; } //KeyboardLayout
public KeyInfo(System.Windows.Input.Key key) { KeyName = key.ToString(); VK_Code = System.Windows.Input.KeyInterop.VirtualKeyFromKey(key); }
private string MapKeyToString(System.Windows.Input.Key key, IntPtr inputHandle) { switch (key) { case System.Windows.Input.Key.Add: case System.Windows.Input.Key.Back: case System.Windows.Input.Key.CapsLock: case System.Windows.Input.Key.D0: case System.Windows.Input.Key.D1: case System.Windows.Input.Key.D2: case System.Windows.Input.Key.D3: case System.Windows.Input.Key.D4: case System.Windows.Input.Key.D5: case System.Windows.Input.Key.D6: case System.Windows.Input.Key.D7: case System.Windows.Input.Key.D8: case System.Windows.Input.Key.D9: case System.Windows.Input.Key.Delete: case System.Windows.Input.Key.Divide: case System.Windows.Input.Key.Down: case System.Windows.Input.Key.End: case System.Windows.Input.Key.Return: case System.Windows.Input.Key.Escape: case System.Windows.Input.Key.F1: case System.Windows.Input.Key.F10: case System.Windows.Input.Key.F11: case System.Windows.Input.Key.F12: case System.Windows.Input.Key.F13: case System.Windows.Input.Key.F14: case System.Windows.Input.Key.F15: case System.Windows.Input.Key.F16: case System.Windows.Input.Key.F17: case System.Windows.Input.Key.F18: case System.Windows.Input.Key.F19: case System.Windows.Input.Key.F2: case System.Windows.Input.Key.F20: case System.Windows.Input.Key.F21: case System.Windows.Input.Key.F22: case System.Windows.Input.Key.F23: case System.Windows.Input.Key.F24: case System.Windows.Input.Key.F3: case System.Windows.Input.Key.F4: case System.Windows.Input.Key.F5: case System.Windows.Input.Key.F6: case System.Windows.Input.Key.F7: case System.Windows.Input.Key.F8: case System.Windows.Input.Key.F9: case System.Windows.Input.Key.Home: case System.Windows.Input.Key.Insert: case System.Windows.Input.Key.RWin: case System.Windows.Input.Key.LWin: case System.Windows.Input.Key.Left: case System.Windows.Input.Key.LeftAlt: case System.Windows.Input.Key.RightAlt: case System.Windows.Input.Key.LeftCtrl: case System.Windows.Input.Key.RightCtrl: case System.Windows.Input.Key.LeftShift: case System.Windows.Input.Key.RightShift: case System.Windows.Input.Key.Multiply: case System.Windows.Input.Key.NumLock: case System.Windows.Input.Key.NumPad0: case System.Windows.Input.Key.NumPad1: case System.Windows.Input.Key.NumPad2: case System.Windows.Input.Key.NumPad3: case System.Windows.Input.Key.NumPad4: case System.Windows.Input.Key.NumPad5: case System.Windows.Input.Key.NumPad6: case System.Windows.Input.Key.NumPad7: case System.Windows.Input.Key.NumPad8: case System.Windows.Input.Key.NumPad9: case System.Windows.Input.Key.PageDown: case System.Windows.Input.Key.PageUp: case System.Windows.Input.Key.PrintScreen: case System.Windows.Input.Key.Right: case System.Windows.Input.Key.Space: case System.Windows.Input.Key.Subtract: case System.Windows.Input.Key.Tab: case System.Windows.Input.Key.Up: return("{" + key.ToString() + "}"); default: return(QAliber.Engine.Win32.LowLevelInput.ConvertKeyToUnicode(key, inputHandle)); } }