Exemple #1
0
        internal static void Update()
        {
            if (!s_window.HasFocus())
            {
                return;
            }

            _wasDown.Clear();
            _keysDown.ForEach((item) =>
            {
                _wasDown.Add(item);
            });
            _keysDown.Clear();

            _mouseState    = Mouse.GetState();
            _keyboardState = Keyboard.GetState();

            inputstring = "";
            foreach (Key key in Enum.GetValues(typeof(Key)))
            {
                if (_keyboardState.IsKeyDown(key) && s_window.HasFocus())
                {
                    _keysDown.Add(key);

                    if (_wasDown.Contains(key))
                    {
                        continue;
                    }

                    if (key == Key.Space)
                    {
                        inputstring += " ";
                    }
                    else if (key == Key.Quote)
                    {
                        inputstring += '"';
                    }
                    else if (key == Key.LBracket)
                    {
                        inputstring += '(';
                    }
                    else if (key == Key.RBracket)
                    {
                        inputstring += ')';
                    }
                    else if (key == Key.Minus)
                    {
                        inputstring += '_';
                    }
                    else if (key == Key.Plus)
                    {
                        inputstring += '+';
                    }
                    else if (key == Key.Period)
                    {
                        inputstring += '.';
                    }

                    else if (key == Key.Number0)
                    {
                        inputstring += "0";
                    }
                    else if (key == Key.Number1)
                    {
                        inputstring += "1";
                    }
                    else if (key == Key.Number2)
                    {
                        inputstring += "2";
                    }
                    else if (key == Key.Number3)
                    {
                        inputstring += "3";
                    }
                    else if (key == Key.Number4)
                    {
                        inputstring += "4";
                    }
                    else if (key == Key.Number5)
                    {
                        inputstring += "5";
                    }
                    else if (key == Key.Number6)
                    {
                        inputstring += "6";
                    }
                    else if (key == Key.Number7)
                    {
                        inputstring += "7";
                    }
                    else if (key == Key.Number8)
                    {
                        inputstring += "8";
                    }
                    else if (key == Key.Number9)
                    {
                        inputstring += "9";
                    }

                    else
                    {
                        string c = key.ToString().ToLower();
                        if (c.Length == 1)
                        {
                            inputstring += c;
                        }
                    }
                }
            }

            var mp = GetMousePos();

            mousepos = new vector((int)s_engine.DEF_WINDOW_WIDTH / 2 - mp.X, (int)s_engine.DEF_WINDOW_HEIGHT / 2 - mp.Y);

            if (mouselock)
            {
                if (mouselocked && !mouselock)
                {
                    mouselocked = false;
                }
                if (!mouselocked && mouselock && s_window.HasFocus())
                {
                    mouselocked = mouselock;
                }

                if (mouselocked)
                {
                    SetMousePos(new vector((int)s_engine.DEF_WINDOW_WIDTH / 2, (int)s_engine.DEF_WINDOW_HEIGHT / 2));
                }
                SetMouseVisible(!mouselocked);
            }
            else
            {
                SetMouseVisible(true);
            }
        }
Exemple #2
0
 public static void SetMousePos(vector vector)
 {
     Mouse.SetPosition((int)vector.x, (int)vector.y);
 }