Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.35 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Net;
  6. using System.Net.Sockets;
  7. using System.Reflection;
  8. using System.Runtime.InteropServices;
  9. using System.Runtime.Serialization.Formatters.Binary;
  10. using System.Text;
  11. using System.Threading;
  12. using System.Threading.Tasks;
  13. using MiscUtil;
  14. namespace RemoteControl
  15. {
  16. class Program
  17. {
  18.  
  19. static void Main(string[] args)
  20. {
  21. while (true)
  22. {
  23. //Send Input
  24. SendInput("192.168.1.15", Keys.A, 50).GetAwaiter().GetResult();
  25. Console.WriteLine("Send Key");
  26. //Free Input
  27. SendInput("192.168.1.15", Keys.None, 50).GetAwaiter().GetResult();
  28. Console.WriteLine("Free Key");
  29. }
  30.  
  31. //Console.ReadKey();
  32. }
  33.  
  34. public class Keys
  35. {
  36. public const uint None = 0;
  37. public const uint A = 1;
  38. public const uint B = 1 << 1;
  39. public const uint X = 1 << 2;
  40. public const uint Y = 1 << 3;
  41. public const uint LEFT_STICK = 1 << 4;
  42. public const uint RIGHT_STICK = 1 << 5;
  43. public const uint L = 1 << 6;
  44. public const uint R = 1 << 7;
  45. public const uint ZL = 1 << 8;
  46. public const uint ZR = 1 << 9;
  47. public const uint PLUS = 1 << 10;
  48. public const uint MINUS = 1 << 11;
  49. public const uint DPAD_LEFT = 1 << 12;
  50. public const uint DOWN_UP = 1 << 13;
  51. public const uint DPAD_RIGHT = 1 << 14;
  52. public const uint DPAD_DOWN = 1 << 15;
  53. public const uint LEFT_ANALOG_LEFT = 1 << 16;
  54. public const uint LEFT_ANALOG_UP = 1 << 17;
  55. public const uint LEFT_ANALOG_RIGHT = 1 << 18;
  56. public const uint LEFT_ANALOG_DOWN = 1 << 19;
  57. public const uint RIGHT_ANALOG_LEFT = 1 << 20;
  58. public const uint RIGHT_ANALOG_UP = 1 << 21;
  59. public const uint RIGHT_ANALOG_RIGHT = 1 << 22;
  60. public const uint RIGHT_ANALOG_DOWN = 1 << 23;
  61. public const uint SL = 1 << 24;
  62. public const uint SR = 1 << 25;
  63. }
  64.  
  65. private static uint get_key_state(uint Key, int Status)
  66. {
  67. uint Out = 0;
  68.  
  69. if (Status >= 0)
  70. {
  71. Out |= Key;
  72. }
  73. else
  74. {
  75. Out &= ~Key;
  76. }
  77.  
  78. return Out;
  79. }
  80.  
  81. public static async Task SendInput(string host, uint Key, int Delay)
  82. {
  83.  
  84. var client = new UdpClient();
  85.  
  86. IPEndPoint endpoint = new IPEndPoint(IPAddress.Parse(host), 8080); // Build a UDP Socket
  87.  
  88. MemoryStream stream = new MemoryStream(26);
  89. using (BinaryWriter writer = new BinaryWriter(stream))
  90. {
  91. writer.Write((UInt16)0x3275);
  92. writer.Write((UInt64)get_key_state(Key, 0));
  93. writer.Write((Int16)0);
  94. writer.Write((Int16)0);
  95. writer.Write((Int16)0);
  96. writer.Write((Int16)0);
  97.  
  98. client.Send(stream.ToArray(), (int)stream.Length, endpoint); // Send Input
  99.  
  100. }
  101.  
  102. await Task.Delay(Delay); // Delay
  103. }
  104. }
  105. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement