/// <summary> /// Sends the KeyPress event to the browser. /// </summary> /// <param name="c">The character associated with the key.</param> /// <param name="ctrlKey">The Control key flag.</param> /// <param name="altKey">The Alt key flag.</param> /// <param name="shiftKey">The Shift key flag.</param> /// <param name="metaKey">The Meta key flag.</param> /// <param name="extendedKey">The extended key flag.</param> public void SendKeyPress(char c, bool ctrlKey = false, bool altKey = false, bool shiftKey = false, bool metaKey = false, bool extendedKey = false) { CefBrowserHost browserHost = this.BrowserObject?.Host; if (browserHost is null) { return; } CefEventFlags modifiers = CefEventFlags.None; if (CefNetApi.IsShiftRequired(c)) { shiftKey = !shiftKey; } if (shiftKey) { modifiers |= CefEventFlags.ShiftDown; } if (altKey) { modifiers |= CefEventFlags.AltDown; } if (ctrlKey) { modifiers |= CefEventFlags.ControlDown; } if (metaKey) { modifiers |= CefEventFlags.CommandDown; } VirtualKeys key = CefNetApi.GetVirtualKey(c); var k = new CefKeyEvent(); k.Type = CefKeyEventType.Char; k.Modifiers = (uint)modifiers; k.IsSystemKey = altKey; k.WindowsKeyCode = PlatformInfo.IsWindows ? c : (int)key; k.NativeKeyCode = CefNetApi.GetNativeKeyCode(c, 0, modifiers, extendedKey); k.Character = c; k.UnmodifiedCharacter = c; this.BrowserObject?.Host?.SendKeyEvent(k); }
private void SendKeyChange(CefKeyEventType eventType, char c, bool ctrlKey, bool altKey, bool shiftKey, bool metaKey, int repeatCount, bool extendedKey) { CefBrowserHost browserHost = this.BrowserObject?.Host; if (browserHost is null) { return; } CefEventFlags modifiers = CefEventFlags.None; if (CefNetApi.IsShiftRequired(c)) { shiftKey = !shiftKey; } VirtualKeys key = CefNetApi.GetVirtualKey(c); if (shiftKey) { modifiers |= CefEventFlags.ShiftDown; } if (altKey) { modifiers |= CefEventFlags.AltDown; } if (ctrlKey) { modifiers |= CefEventFlags.ControlDown; } if (metaKey) { modifiers |= CefEventFlags.CommandDown; } var k = new CefKeyEvent(); k.Type = eventType; k.Modifiers = (uint)modifiers; k.IsSystemKey = altKey; k.WindowsKeyCode = (int)key; k.NativeKeyCode = CefNetApi.GetNativeKeyCode(eventType, repeatCount, key, modifiers, extendedKey); k.Character = c; k.UnmodifiedCharacter = c; this.BrowserObject?.Host?.SendKeyEvent(k); }
private void SendKeyChange(CefKeyEventType eventType, VirtualKeys key, bool ctrlKey, bool altKey, bool shiftKey, bool metaKey, int repeatCount, bool extendedKey) { if (key < VirtualKeys.None || key > VirtualKeys.OemClear) { throw new ArgumentOutOfRangeException(nameof(key)); } CefBrowserHost browserHost = this.BrowserObject?.Host; if (browserHost is null) { return; } CefEventFlags modifiers = CefEventFlags.None; if (shiftKey) { modifiers |= CefEventFlags.ShiftDown; } if (altKey) { modifiers |= CefEventFlags.AltDown; } if (ctrlKey) { modifiers |= CefEventFlags.ControlDown; } if (metaKey) { modifiers |= CefEventFlags.CommandDown; } var k = new CefKeyEvent(); k.Type = eventType; k.Modifiers = (uint)modifiers; k.IsSystemKey = altKey; k.WindowsKeyCode = (int)key; k.NativeKeyCode = CefNetApi.GetNativeKeyCode(eventType, repeatCount, key, modifiers, extendedKey); k.Character = (char)key; k.UnmodifiedCharacter = (char)key; this.BrowserObject?.Host?.SendKeyEvent(k); }
/// <summary> /// Translates a virtual key to the corresponding native key code for the current keyboard. /// </summary> /// <param name="isRepeat">The repeat flag.</param> /// <param name="eventType">The key event type.</param> /// <param name="modifiers">A bitwise combination of the <see cref="CefEventFlags"/> values.</param> /// <param name="key">The virtual key.</param> /// <param name="isExtended">The extended key flag.</param> /// <returns>A native key code for the current keyboard.</returns> public static int ToNativeKeyCode(this VirtualKeys key, CefKeyEventType eventType, bool isRepeat, CefEventFlags modifiers, bool isExtended) { return(CefNetApi.GetNativeKeyCode(eventType, isRepeat ? 1 : 0, key, modifiers, isExtended)); }