コード例 #1
0
        public static void listenUDP(int port)
        {
            UdpClient  client  = new UdpClient(port);
            IPEndPoint groupEP = new IPEndPoint(IPAddress.Any, port);

            byte[]            received_byte_array;
            handleBtnDelegate handleBtn,
                              keydown = new handleBtnDelegate(InputSimulator.SimulateKeyDown),
                              keyup   = new handleBtnDelegate(InputSimulator.SimulateKeyUp);


            try
            {
                while (!done)
                {
                    Console.WriteLine("done:" + done);
                    received_byte_array = client.Receive(ref groupEP);
                    byte btn = received_byte_array[0], stat = received_byte_array[1];
                    if (stat == 1)
                    {
                        handleBtn = keydown;
                    }
                    else
                    {
                        handleBtn = keyup;
                    }
                    switch (btn)
                    {
                    case 1:
                        handleBtn(VirtualKeyCode.VK_W);
                        break;

                    case 2:
                        handleBtn(VirtualKeyCode.VK_D);
                        break;

                    case 3:
                        handleBtn(VirtualKeyCode.VK_S);
                        break;

                    case 4:
                        handleBtn(VirtualKeyCode.VK_A);
                        break;

                    case 5:
                        handleBtn(VirtualKeyCode.VK_J);
                        break;

                    case 6:
                        handleBtn(VirtualKeyCode.VK_K);

                        break;

                    default:
                        Console.WriteLine("default");
                        break;
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
            }
            client.Close();
        }
コード例 #2
0
ファイル: Form1.cs プロジェクト: tensorfly/pcontroller
        public static void listenUDP(int port) {
            
            UdpClient client = new UdpClient(port);
            IPEndPoint groupEP = new IPEndPoint(IPAddress.Any, port);

            byte[] received_byte_array;
            handleBtnDelegate handleBtn,
            keydown = new handleBtnDelegate(InputSimulator.SimulateKeyDown),
            keyup = new handleBtnDelegate(InputSimulator.SimulateKeyUp);

            
            try
            {
                while (!done)
                {
                    Console.WriteLine("done:" + done);
                    received_byte_array = client.Receive(ref groupEP);
                    byte btn = received_byte_array[0], stat = received_byte_array[1];
                    if (stat == 1)
                    {
                        handleBtn = keydown;
                    }
                    else {
                        handleBtn = keyup;
                    }
                    switch (btn) { 
                        case 1:
                            handleBtn(VirtualKeyCode.VK_W);
                            break;
                        case 2:
                            handleBtn(VirtualKeyCode.VK_D);
                            break;
                        case 3:
                            handleBtn(VirtualKeyCode.VK_S);
                            break;
                        case 4:
                            handleBtn(VirtualKeyCode.VK_A);
                            break;
                        case 5:
                            handleBtn(VirtualKeyCode.VK_J);
                            break;
                        case 6:
                            handleBtn(VirtualKeyCode.VK_K);
                            
                            break;
                        default:
                            Console.WriteLine("default");
                            break;
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
            }
            client.Close(); 
        
        }