private void OnKeyPressed(object sender, RawInputEventArg e)
        {
            string deviceUniqueID = e.KeyPressEvent.DeviceHandle.ToString();

            Keys key = GetKey(e.KeyPressEvent.VKey);

            if (key != Keys.None)
            {
                if (!keyboardsKeyStores.ContainsKey(deviceUniqueID))
                {
                    keyboardsKeyStores.Add(deviceUniqueID, new KeyStateStore());
                }

                if (keyboardsKeyStores.TryGetValue(deviceUniqueID, out KeyStateStore keyStateStore))
                {
                    keyStateStore.SetKeyState((int)key, e.KeyPressEvent.IsPressed());
                }
            }
            else
            {
                Console.WriteLine($"Unknown key \"{KeyMapper.GetMicrosoftKeyName(e.KeyPressEvent.VKey)}\"");
            }

            //Fixes input not working inside of text boxes and chat boxes
            if (e.KeyPressEvent.IsPressed() && (deviceUniqueID == attachedKeyboardID || (String.IsNullOrWhiteSpace(attachedKeyboardID) && Game1.game1.IsActive)))
            {
                char c = KeyToChar(key, GetAnyPressedKeys().Contains(Keys.LeftShift));

                if ((int)c != 0)                //Prevents sending strange keys
                {
                    Game1.keyboardDispatcher.Subscriber?.RecieveTextInput(c);
                }

                switch (key)
                {
                case (Keys.Back): Game1.keyboardDispatcher.Subscriber?.RecieveCommandInput('\b'); break;

                case (Keys.Enter): Game1.keyboardDispatcher.Subscriber?.RecieveCommandInput('\r'); break;

                case (Keys.Tab): Game1.keyboardDispatcher.Subscriber?.RecieveCommandInput('\t'); break;
                }
            }
        }
Exemple #2
0
            private void OnKeyPressed(object sender, RawInputEventArg e)
            {
                string deviceUniqueID = e.KeyPressEvent.DeviceHandle.ToString();

                Keys key = GetKey(e.KeyPressEvent.VKey);

                if (key != Keys.None)
                {
                    if (!keyboardsKeyStores.ContainsKey(deviceUniqueID))
                    {
                        keyboardsKeyStores.Add(deviceUniqueID, new KeyStateStore());
                    }

                    KeyStateStore keyStateStore;
                    if (keyboardsKeyStores.TryGetValue(deviceUniqueID, out keyStateStore))
                    {
                        keyStateStore.SetKeyState((int)key, e.KeyPressEvent.IsPressed());
                    }
                }
                else
                {
                    Console.WriteLine($"Unknown key \"{KeyMapper.GetMicrosoftKeyName(e.KeyPressEvent.VKey)}\"");
                }
            }