/// <summary> /// Gets an Awesomium <see cref="WebKeyboardEvent"/> equivalent of a Windows Forms key-down or key-up event. /// </summary> /// <param name="eventType"> /// Indicates if this is a key-down or key-up event. /// </param> /// <param name="e"> /// The Windows Forms key-down or key-up event arguments. /// </param> /// <returns> /// An instance of a <see cref="WebKeyboardEvent"/> representing the Awesomium equivalent of a /// Windows Forms key-down or key-up event. /// </returns> public static WebKeyboardEvent GetKeyboardEvent(WebKeyType eventType, KeyEventArgs e) { WebKeyModifiers modifiers = 0; if (e.Alt) { modifiers |= WebKeyModifiers.AltKey; } if (e.Shift) { modifiers |= WebKeyModifiers.ShiftKey; } if (e.Control) { modifiers |= WebKeyModifiers.ControlKey; } WebKeyboardEvent keyEvent = new WebKeyboardEvent() { Type = eventType, VirtualKeyCode = (VirtualKey)e.KeyCode, Modifiers = modifiers }; return(keyEvent); }
void InjectKeyDown(WebKeyboardEvent keyEvent, ushort keyValue) { keyEvent.type = WebKeyType.KeyDown; keyEvent.virtualKeyCode = keyValue; keyEvent.nativeKeyCode = keyValue; webView.InjectKeyboardEvent(keyEvent); }
public void typeKeys(string key) { for (int i = 0; i < key.Length; i++) { WebKeyboardEvent keyEvent = new WebKeyboardEvent(); //keyEvent.type = WebKeyType.KeyDown; keyEvent.Type = WebKeyboardEventType.KeyDown; //keyEvent.virtualKeyCode = key[i]; keyEvent.VirtualKeyCode = (VirtualKey)key[i]; webView.InjectKeyboardEvent(keyEvent); //keyEvent.type = WebKeyType.Char; keyEvent.Type = WebKeyboardEventType.Char; //keyEvent.text = new ushort[] { key[i], 0, 0, 0 }; keyEvent.Text = new ushort[] { key[i], 0, 0, 0 }.ToString(); webView.InjectKeyboardEvent(keyEvent); //keyEvent.type = WebKeyType.KeyUp; keyEvent.Type = WebKeyboardEventType.KeyUp; //keyEvent.virtualKeyCode = key[i]; keyEvent.VirtualKeyCode = (VirtualKey)key[i]; webView.InjectKeyboardEvent(keyEvent); } }
void HandleKeyboardEvent(Event e, bool addModifier = true, bool overrideChar = false, char c = '\0') { if (!disableKeyInput) { if (!DynamicKeyInputAllowed || (GameGUI.Inst.GuiLayerHasInputFocus && GameGUI.Inst.guiLayer.htmlPanel.browserTexture != this)) { RaiseKeyEntryBlocked(e.keyCode); } else { WebKeyboardEvent webEvent = e.GetKeyboardEvent(); if (addModifier && e.command) { webEvent.Modifiers |= WebKeyModifiers.MetaKey; } if (overrideChar) { if (webEvent.Text == null) { webEvent.Text = new ushort[1]; } webEvent.Text[0] = (ushort)c; } webView.InjectKeyboardEvent(webEvent); } } }
public void KeyUp(WebKeyboardEvent webKeyboardEvent) { if (webView != null && webView.IsLive) { webView.InjectKeyboardEvent(webKeyboardEvent); } }
/// <summary> /// Allows keys to be passed to the view that the mouse is over. /// </summary> /// <param name="k"></param> /// <param name="x"></param> /// <param name="y"></param> public static void InjectKey(Keyboard.Key k, int x, int y) { if (Tabs.Count == 0) { return; } foreach (BrowserTab t in Tabs) { if (t.MouseOver(x, y) && t.KeyEvents) { Console.WriteLine("Sending " + k.ToString() + " to " + t.ID); WebCore.QueueWork(t.MyTab, () => { if (k != Keyboard.Key.F5) { WebKeyboardEvent keyboardEvent = new WebKeyboardEvent(); keyboardEvent.Text = k.ToString(); keyboardEvent.Type = WebKeyboardEventType.Char; t.MyTab.InjectKeyboardEvent(keyboardEvent); } else { Console.WriteLine("Refreshing tab..."); t.MyTab.Source = new Uri(t.url); } }); return; } } }
void WebForm_KeyUp(object sender, KeyEventArgs e) { WebKeyboardEvent keyEvent = new WebKeyboardEvent(); keyEvent.type = WebKeyType.KeyUp; keyEvent.virtualKeyCode = (int)e.KeyCode; webView.InjectKeyboardEvent(keyEvent); }
void WebForm_KeyPress(object sender, KeyPressEventArgs e) { WebKeyboardEvent keyEvent = new WebKeyboardEvent(); keyEvent.type = WebKeyType.Char; keyEvent.text = new ushort[] { e.KeyChar, 0, 0, 0 }; webView.InjectKeyboardEvent(keyEvent); }
public void InjectKeyboardEvent(int msg, int wParam, int lParam) { //webView.InjectKeyboardEventWin((int)msg, (int)wParam, (int)lParam); const Modifiers modifiers = new Modifiers(); var keyEvent = new WebKeyboardEvent((uint)msg, (IntPtr)wParam, (IntPtr)lParam, modifiers); WebView.InjectKeyboardEvent(keyEvent); }
/// <summary> /// Gets an Awesomium <see cref="WebKeyboardEvent"/> equivalent of a Windows Forms key-press event. /// </summary> /// <param name="e"> /// The Windows Forms key-press event arguments. /// </param> /// <returns> /// An instance of a <see cref="WebKeyboardEvent"/> representing the Awesomium equivalent of a /// Windows Forms key-press event. /// </returns> public static WebKeyboardEvent GetKeyboardEvent(KeyPressEventArgs e) { WebKeyboardEvent keyEvent = new WebKeyboardEvent { Type = WebKeyType.Char, Text = new ushort[] { e.KeyChar, 0, 0, 0 } }; return(keyEvent); }
private void OnGUI() { if (!WebCore.IsRunning) { return; } Event e = Event.current; // We only inject keyboard input when the GameObject has focus if (e.isKey == true && isFocused == true) { if (e.type == EventType.KeyDown) { if (e.character == 0) { WebKeyboardEvent keyEvent = new WebKeyboardEvent(); keyEvent.Type = WebKeyType.KeyDown; keyEvent.VirtualKeyCode = MapKeys(e); keyEvent.Modifiers = MapModifiers(e); webView.InjectKeyboardEvent(keyEvent); } else { WebKeyboardEvent keyEvent = new WebKeyboardEvent(); keyEvent.Type = WebKeyType.Char; keyEvent.Text = new ushort[] { e.character, 0, 0, 0 }; keyEvent.Modifiers = MapModifiers(e); webView.InjectKeyboardEvent(keyEvent); } } if (e.type == EventType.KeyUp) { WebKeyboardEvent keyEvent = new WebKeyboardEvent(); keyEvent.Type = WebKeyType.KeyUp; keyEvent.VirtualKeyCode = MapKeys(e); keyEvent.Modifiers = MapModifiers(e); webView.InjectKeyboardEvent(keyEvent); } } // We unfocus each WebView whenever a MouseDown event is encountered in OnGUI. // The actual focusing of a specific element occurs in OnMouseDown if (e.type == EventType.MouseDown) { Unfocus(); } if (e.type == EventType.ScrollWheel && isScrollable == true) { webView.InjectMouseWheel((int)e.delta.y * -10); } }
public void InjectKeyboardEvent(Keys key) { //TODO: add support for key down and keyup state as well as non-character keys char keyChar = (char)key; WebKeyboardEvent keyDown = new WebKeyboardEvent(); keyDown.Type = WebKeyType.Char; keyDown.Text = new ushort[] { keyChar, 0, 0, 0 }; webView.InjectKeyboardEvent(keyDown); }
/// <summary> /// Allows keys to be passed to the view that the mouse is over. /// </summary> /// <param name="k"></param> /// <param name="x"></param> /// <param name="y"></param> public static void InjectKey(Keyboard.Key k, int x, int y) { foreach (BrowserTab t in Tabs) { if (t.MouseOver(x, y) && t.KeyEvents) { awesomiumContext.Send(state => { WebKeyboardEvent keyboardEvent = new WebKeyboardEvent(); keyboardEvent.Text = k.ToString(); keyboardEvent.Type = WebKeyboardEventType.Char; t.MyTab.InjectKeyboardEvent(keyboardEvent); }, null); } } }
/// <summary> /// Handles key releases. /// </summary> /// <param name="key">The released key.</param> private void HandleKeyReleased(Keys key) { if (_screens.Count < 1) { return; } var e = new WebKeyboardEvent { Type = WebKeyboardEventType.KeyUp, IsSystemKey = false, VirtualKeyCode = (VirtualKey)key }; SetModifiers(e); _screens.Peek().InjectKeyboardEvent(e); }
/// <summary> /// Sets the currently active keyboard modifiers for the specified event. /// </summary> /// <param name="e">The event.</param> private static void SetModifiers(WebKeyboardEvent e) { if (Keyboard.GetState().IsKeyDown(Keys.LeftControl) || Keyboard.GetState().IsKeyDown(Keys.RightControl)) { e.Modifiers |= Modifiers.ControlKey; } if (Keyboard.GetState().IsKeyDown(Keys.LeftShift) || Keyboard.GetState().IsKeyDown(Keys.RightShift)) { e.Modifiers |= Modifiers.ShiftKey; } if (Keyboard.GetState().IsKeyDown(Keys.LeftAlt) || Keyboard.GetState().IsKeyDown(Keys.RightAlt)) { e.Modifiers |= Modifiers.ShiftKey; } }
/// <summary> /// Handles character input. /// </summary> /// <param name="character">The typed character.</param> private void HandleCharacterEntered(char character) { if (_screens.Count < 1) { return; } var e = new WebKeyboardEvent { Type = WebKeyboardEventType.Char, IsSystemKey = false, Text = new string(character, 1), UnmodifiedText = new string(character, 1), VirtualKeyCode = (VirtualKey)VkKeyScan(character), NativeKeyCode = character }; SetModifiers(e); _screens.Peek().InjectKeyboardEvent(e); }
public void KeyUp(WebKeyboardEvent webKeyboardEvent) { if (webView != null && webView.IsLive) webView.InjectKeyboardEvent(webKeyboardEvent); }
private Int32 ProcessMessages(Int32 code, Int32 wParam, ref Message lParam) { if (this.Enabled && code == 0 && wParam == 1) { bool processed = false; switch ((WindowsMessage)lParam.Msg) { case WindowsMessage.KeyDown: case WindowsMessage.KeyUp: case WindowsMessage.Char: WebKeyboardEvent keyboardEvent = new WebKeyboardEvent((uint)lParam.Msg, lParam.WParam, lParam.LParam, 0); awesomiumContext.Post(state => { if (!WebView.IsLive) { return; } WebView.InjectKeyboardEvent(keyboardEvent); }, null); processed = true; break; case WindowsMessage.MouseWheel: var delta = (((Int32)lParam.WParam) >> 16); awesomiumContext.Post(state => { if (!WebView.IsLive) { return; } WebView.InjectMouseWheel(delta / SystemMetrics.MouseWheelScrollDelta * 16 * SystemMetrics.MouseWheelScrollLines, 0); }, null); processed = true; break; } if (!processed) { WindowsMessage message = (WindowsMessage)lParam.Msg; awesomiumContext.Post(state => { if (!WebView.IsLive) { return; } switch (message) { case WindowsMessage.MouseMove: var mouse = Mouse.GetState(); WebView.InjectMouseMove(mouse.X - area.X, mouse.Y - area.Y); break; case WindowsMessage.LeftButtonDown: WebView.InjectMouseDown(MouseButton.Left); break; case WindowsMessage.LeftButtonUp: WebView.InjectMouseUp(MouseButton.Left); break; case WindowsMessage.LeftButtonDoubleClick: WebView.InjectMouseDown(MouseButton.Left); break; case WindowsMessage.RightButtonDown: WebView.InjectMouseDown(MouseButton.Right); break; case WindowsMessage.RightButtonUp: WebView.InjectMouseUp(MouseButton.Right); break; case WindowsMessage.RightButtonDoubleClick: WebView.InjectMouseDown(MouseButton.Right); break; case WindowsMessage.MiddleButtonDown: WebView.InjectMouseDown(MouseButton.Middle); break; case WindowsMessage.MiddleButtonUp: WebView.InjectMouseUp(MouseButton.Middle); break; case WindowsMessage.MiddleButtonDoubleClick: WebView.InjectMouseDown(MouseButton.Middle); break; } }, null); } User32.TranslateMessage(ref lParam); } return(User32.CallNextHookEx(IntPtr.Zero, code, wParam, ref lParam)); }
/// <summary> /// Gets an Awesomium <see cref="WebKeyboardEvent"/> equivalent of a Windows Forms key-press event. /// </summary> /// <param name="e"> /// The Windows Forms key-press event arguments. /// </param> /// <returns> /// An instance of a <see cref="WebKeyboardEvent"/> representing the Awesomium equivalent of a /// Windows Forms key-press event. /// </returns> public static WebKeyboardEvent GetKeyboardEvent( KeyPressEventArgs e ) { WebKeyboardEvent keyEvent = new WebKeyboardEvent { Type = WebKeyType.Char, Text = new ushort[] { e.KeyChar, 0, 0, 0 } }; return keyEvent; }
/// <summary> /// Gets an Awesomium <see cref="WebKeyboardEvent"/> equivalent of a Windows Forms key-down or key-up event. /// </summary> /// <param name="eventType"> /// Indicates if this is a key-down or key-up event. /// </param> /// <param name="e"> /// The Windows Forms key-down or key-up event arguments. /// </param> /// <returns> /// An instance of a <see cref="WebKeyboardEvent"/> representing the Awesomium equivalent of a /// Windows Forms key-down or key-up event. /// </returns> public static WebKeyboardEvent GetKeyboardEvent( WebKeyType eventType, KeyEventArgs e ) { WebKeyModifiers modifiers = 0; if ( e.Alt ) modifiers |= WebKeyModifiers.AltKey; if ( e.Shift ) modifiers |= WebKeyModifiers.ShiftKey; if ( e.Control ) modifiers |= WebKeyModifiers.ControlKey; WebKeyboardEvent keyEvent = new WebKeyboardEvent() { Type = eventType, VirtualKeyCode = (VirtualKey)e.KeyCode, Modifiers = modifiers }; return keyEvent; }
private void OnGUI() { if (!WebCore.IsRunning) return; Event e = Event.current; // We only inject keyboard input when the GameObject has focus if (e.isKey == true && isFocused == true) { if (e.type == EventType.KeyDown) { if (e.character == 0) { WebKeyboardEvent keyEvent = new WebKeyboardEvent(); keyEvent.Type = WebKeyType.KeyDown; keyEvent.VirtualKeyCode = MapKeys(e); keyEvent.Modifiers = MapModifiers(e); webView.InjectKeyboardEvent(keyEvent); } else { WebKeyboardEvent keyEvent = new WebKeyboardEvent(); keyEvent.Type = WebKeyType.Char; keyEvent.Text = new ushort[] { e.character, 0, 0, 0 }; keyEvent.Modifiers = MapModifiers(e); webView.InjectKeyboardEvent(keyEvent); } } if (e.type == EventType.KeyUp) { WebKeyboardEvent keyEvent = new WebKeyboardEvent(); keyEvent.Type = WebKeyType.KeyUp; keyEvent.VirtualKeyCode = MapKeys(e); keyEvent.Modifiers = MapModifiers(e); webView.InjectKeyboardEvent(keyEvent); } } // We unfocus each WebView whenever a MouseDown event is encountered in OnGUI. // The actual focusing of a specific element occurs in OnMouseDown if (e.type == EventType.MouseDown) { Unfocus(); } if (e.type == EventType.ScrollWheel && isScrollable == true) { webView.InjectMouseWheel((int)e.delta.y * -10); } }
/// <summary> /// Injects a keyboard event. /// </summary> /// <param name="keyEvent"> /// The keyboard event to inject. You'll need to initialize the members of the passed /// <see cref="WebKeyboardEvent"/>, yourself. /// </param> /// <remarks> /// <note type="inherit"> /// <see cref="WebControl"/> handles this internally. Inheritors do not need to call this method unless /// they implement custom logic. /// </note> /// <note type="caution"> /// For performance reasons, no validity check is performed when calling protected members. /// Inheritors should perform any such checks (see <see cref="IsLive"/>), before calling these members. /// </note> /// </remarks> protected void InjectKeyboardEvent( WebKeyboardEvent keyEvent ) { awe_webview_inject_keyboard_event( Instance, keyEvent ); }
private extern static void awe_webview_inject_keyboard_event( IntPtr webview, WebKeyboardEvent key_event );
public void InjectKeyboardEvent(WebKeyboardEvent keyEvent) { awe_webview_inject_keyboard_event(instance, keyEvent); }
public void InjectKeyboardEvent( WebKeyboardEvent keyEvent ) { VerifyLive(); awe_webview_inject_keyboard_event( Instance, keyEvent ); }
public void Type(string input) { var ev = new WebKeyboardEvent(); foreach (char c in input) { ev.Text = c.ToString(CultureInfo.InvariantCulture); ev.KeyIdentifier = c.ToString(CultureInfo.InvariantCulture); BrowserThread.ExecuteAction(() => { ev.Type = WebKeyboardEventType.KeyDown; _view.InjectKeyboardEvent(ev); ev.Type = WebKeyboardEventType.Char; _view.InjectKeyboardEvent(ev); ev.Type = WebKeyboardEventType.KeyUp; _view.InjectKeyboardEvent(ev); }); } }
void InjectKeyPress(WebKeyboardEvent keyEvent, ushort keyValue) { keyEvent.type = WebKeyType.Char; keyEvent.text = new ushort[] { keyValue, 0, 0, 0 }; webView.InjectKeyboardEvent(keyEvent); }
public void InjectKeyboardEvent() { Microsoft.Xna.Framework.Input.Keys[] keys = inputHandler.KeyboardManager.KeysPressed(); WebKeyboardEvent keyEvent = new WebKeyboardEvent(); ushort keyValue = 0; List <Microsoft.Xna.Framework.Input.Keys> regularKeys = new List <Microsoft.Xna.Framework.Input.Keys>(); bool IsShiftDown = false; bool IsCtrlDown = false; bool IsAltDown = false; bool IsWinDown = false; // what special keys are down? for (int k = keys.Length - 1; k >= 0; k--) { switch (keys[k]) { case Microsoft.Xna.Framework.Input.Keys.LeftShift: case Microsoft.Xna.Framework.Input.Keys.RightShift: IsShiftDown = true; break; case Microsoft.Xna.Framework.Input.Keys.LeftControl: case Microsoft.Xna.Framework.Input.Keys.RightControl: IsCtrlDown = true; break; case Microsoft.Xna.Framework.Input.Keys.LeftAlt: case Microsoft.Xna.Framework.Input.Keys.RightAlt: IsAltDown = true; break; case Microsoft.Xna.Framework.Input.Keys.LeftWindows: case Microsoft.Xna.Framework.Input.Keys.RightWindows: IsWinDown = true; break; default: regularKeys.Add(keys[k]); break; } } foreach (Microsoft.Xna.Framework.Input.Keys key in regularKeys) { switch (key) { case Microsoft.Xna.Framework.Input.Keys.Add: keyValue = (ushort)'+'; InjectKeyPress(keyEvent, keyValue); break; case Microsoft.Xna.Framework.Input.Keys.Back: keyValue = (ushort)'\b'; InjectKeyDown(keyEvent, keyValue); break; case Microsoft.Xna.Framework.Input.Keys.Delete: keyValue = (ushort)127; InjectKeyDown(keyEvent, keyValue); break; default: keyValue = (ushort)key; if (!IsShiftDown) { keyValue += 32; } InjectKeyPress(keyEvent, keyValue); break; } } }