Exemple #1
0
        public virtual IMessage Decode(byte[] bytes)
        {
            header.Clear();
            header.Decode(bytes, 0);

            switch (header.GetMessageType())
            {
            case MessageType.Keyboard:
                keyboard.Clear();
                keyboard.Decode(bytes, 0);
                return(keyboard);

            case MessageType.Rocker:
                rocker.Clear();
                rocker.Decode(bytes, 0);
                return(rocker);

            case MessageType.Gyro:
                gyro.Clear();
                gyro.Decode(bytes, 0);
                return(gyro);
            }

            return(null);
        }
        //键盘消息
        public static IMessage Keyboard(byte hid, string keyName, KeyboardState state)
        {
            int keycode = KeyMap[hid][keyName];

            MessageKeyboard msg = new MessageKeyboard();

            msg.Clear();
            msg.TimeStamp = SystemTime.LowClientNow();
            msg.Hid       = hid;
            msg.KeyCode   = (KeyCode2)keycode;
            msg.State     = state;
            return(msg);
        }
Exemple #3
0
        public IMessage Decode(string data)
        {
            keyboard.Clear();

            string[] keyData  = data.Split('-');
            KeyCode2 kc       = (KeyCode2)int.Parse(keyData[0]);
            string   keyState = keyData[1];

            //TODO 1p,2p 赋值
            keyboard.KeyCode = kc;
            if (keyState.Equals("down"))
            {
                keyboard.State = KeyboardState.KeyDown;
            }
            else if (keyState.Equals("up"))
            {
                keyboard.State = KeyboardState.KeyUp;
            }

            return(keyboard);
        }