Exemple #1
0
 private static void KeyboardNetworkTimerHandler(object state)
 {
     lock (KeyboardThread)
     {
         KeyboardNetworkSocket.SendTo(KeyboardStatePacket.Packet.ToBytesArray(), IPEndPoint);
         LastKeyboardKeyState.CopyFrom(KeyboardStatePacket.KeyState);
     }
 }
Exemple #2
0
        public static BitField Deserialize(byte[] buffer, int offset)
        {
            var size = Protocol.NullMaskLength.Read(buffer, offset);

            var value = new BitField(size);

            value.CopyFrom(buffer, offset + Protocol.NullMaskLength.Size);

            return(value);
        }
Exemple #3
0
 private static void MouseNetworkTimerHandler(object state)
 {
     lock (MouseThread)
     {
         MouseNetworkSocket.SendTo(MouseStatePacket.Packet.ToBytesArray(), IPEndPoint);
         LastMouseButtonState.CopyFrom(MouseStatePacket.Buttons);
         MouseStatePacket.XDelta            = MouseStatePacket.YDelta = 0;
         MouseStatePacket.Packet.WheelDelta = 0;
     }
 }
Exemple #4
0
        public MainForm()
        {
            InitializeComponent();

            ListenerThread = new Thread(() =>
            {
                var socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
                socket.Bind(new IPEndPoint(IPAddress.Any, Settings.Default.ListeningPort));

                var oldbuttons  = new BitField(8);
                var oldkeystate = new BitField(256);

                var recvbuffer        = new byte[40];
                var rawmousepacket    = new byte[Marshal.SizeOf <MouseStatePacketType>()];
                var rawkeyboardpacket = new byte[Marshal.SizeOf <KeyboardStatePacketType>()];

                while (true)
                {
                    socket.Receive(recvbuffer);

                    switch (recvbuffer[0])
                    {
                    case 1:
                        {
                            // mouse
                            Array.Copy(recvbuffer, rawmousepacket, rawmousepacket.Length);
                            var packetwrapper = new MouseStatePacketWrapperType(rawmousepacket.ToObject <MouseStatePacketType>());
                            InputSimulator.ApplyPacket(packetwrapper, oldbuttons);
                            oldbuttons.CopyFrom(packetwrapper.Buttons);
                        }

                        break;

                    case 2:
                        {
                            // keyboard
                            Array.Copy(recvbuffer, rawkeyboardpacket, rawkeyboardpacket.Length);
                            var packetwrapper = new KeyboardStatePacketWrapperType(rawkeyboardpacket.ToObject <KeyboardStatePacketType>());
                            InputSimulator.ApplyPacket(packetwrapper, oldkeystate);
                            oldkeystate.CopyFrom(packetwrapper.KeyState);
                        }

                        break;

                    default:
                        continue;
                    }
                }
            })
            {
                Name = "Listener Thread", IsBackground = true
            };
            ListenerThread.Start();
        }