private void HandleKeyInput()
        {
            List <Event> keyEvents = browser.UIHandler.KeyEvents;

            if (keyEvents.Count == 0)
            {
                return;
            }
            foreach (Event item in keyEvents)
            {
                int windowsKeyCode = KeyMappings.GetWindowsKeyCode(item);
                if (item.character == '\n')
                {
                    item.character = '\r';
                }
                if (item.character != 0 && item.type == EventType.KeyDown)
                {
                    BrowserNative.zfb_characterEvent(browser.browserId, item.character, windowsKeyCode);
                }
                else
                {
                    BrowserNative.zfb_keyEvent(browser.browserId, item.type == EventType.KeyDown, windowsKeyCode);
                }
            }
        }
        public void HandleFocusLoss()
        {
            foreach (var keyCode in keysToReleaseOnFocusLoss)
            {
                //Debug.Log("Key " + keyCode + " is held, release");
                var wCode = KeyMappings.GetWindowsKeyCode(new Event()
                {
                    keyCode = keyCode
                });
                BrowserNative.zfb_keyEvent(browser.browserId, false, wCode);
            }

            keysToReleaseOnFocusLoss.Clear();
        }
        private void HandleKeyInput(List <Event> keyEvents)
        {
#if ZF_OSX
            ReconstructInputs(keyEvents);
#endif

            foreach (var ev in keyEvents)
            {
                var keyCode = KeyMappings.GetWindowsKeyCode(ev);
                if (ev.character == '\n')
                {
                    ev.character = '\r';                              //'cuz that's what Chromium expects
                }
                if (ev.character == 0)
                {
                    if (ev.type == EventType.KeyDown)
                    {
                        keysToReleaseOnFocusLoss.Add(ev.keyCode);
                    }
                    else
                    {
                        keysToReleaseOnFocusLoss.Remove(ev.keyCode);
                    }
                }

//			if (false) {
//				if (ev.character != 0) Debug.Log("k >>> " + ev.character);
//				else if (ev.type == EventType.KeyUp) Debug.Log("k ^^^ " + ev.keyCode);
//				else if (ev.type == EventType.KeyDown) Debug.Log("k vvv " + ev.keyCode);
//			}

                FireCommands(ev);

                if (ev.character != 0 && ev.type == EventType.KeyDown)
                {
#if ZF_LINUX
                    //It seems, on Linux, we don't get keydown, keypress, keyup, we just get a keypress, keyup.
                    //So, fire the keydown just before the keypress.
                    BrowserNative.zfb_keyEvent(browser.browserId, true, keyCode);
                    //Thanks for being consistent, Unity.
#endif

                    BrowserNative.zfb_characterEvent(browser.browserId, ev.character, keyCode);
                }
                else
                {
                    BrowserNative.zfb_keyEvent(browser.browserId, ev.type == EventType.KeyDown, keyCode);
                }
            }
        }
Exemple #4
0
        private void HandleMessage(string message)
        {
            var msg = JSONNode.Parse(message);


            switch ((string)msg["type"])
            {
            case "mouseDown":
            case "mouseUp": {
                int         button = msg["button"];
                MouseButton flag   = 0;
                if (button == 0)
                {
                    flag = MouseButton.Left;
                }
                else if (button == 1)
                {
                    flag = MouseButton.Right;
                }
                else if (button == 2)
                {
                    flag = MouseButton.Middle;
                }

                if (msg["type"] == "mouseDown")
                {
                    MouseButtons |= flag;
                }
                else
                {
                    MouseButtons &= ~flag;
                }

                break;
            }

            case "mouseMove": {
                var screenPos = new Vector2(msg["x"], msg["y"]);
                screenPos.x   = screenPos.x / browser.Size.x;
                screenPos.y   = screenPos.y / browser.Size.y;
                MousePosition = screenPos;
                //Debug.Log("mouse now at " + screenPos);
                break;
            }

            case "mouseFocus":
                MouseHasFocus = msg["focus"];
                break;

            case "keyboardFocus":
                KeyboardHasFocus = msg["focus"];
                break;

            case "mouseScroll": {
                const float mult = 1 / 3f;
                MouseScroll += new Vector2(msg["x"], msg["y"]) * mult;
                break;
            }

            case "keyDown":
            case "keyUp": {
                var ev = new Event();
                ev.type      = msg["type"] == "keyDown" ? EventType.KeyDown : EventType.KeyUp;
                ev.character = (char)0;
                ev.keyCode   = KeyMappings.GetUnityKeyCode(msg["code"]);
                SetMods(ev);

                //Debug.Log("Convert wkc " + (int)msg["code"] + " to ukc " + ev.keyCode);

                KeyEvents.Add(ev);
                break;
            }

            case "keyPress": {
                string characters = msg["characters"];
                foreach (char c in characters)
                {
                    var ev = new Event();
                    ev.type = EventType.KeyDown;
                    SetMods(ev);
                    ev.character = c;
                    ev.keyCode   = 0;

                    KeyEvents.Add(ev);
                }
                break;
            }

            case "resize":
                //on OS X (editor at least), resizing hangs the update loop, so we suddenly end up with a bajillion resize
                //messages we were unable to process. Just record it here and when we've processed everything we'll resize
                delayedResize.x = msg["w"];
                delayedResize.y = msg["h"];
                break;

            case "close":
                Destroy(gameObject);
                break;

            default:
                Debug.LogWarning("Unknown window event: " + msg.AsJSON);
                break;
            }
        }