Advertisement
Guest User

Untitled

a guest
Oct 27th, 2016
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.10 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading;
  9. using System.Threading.Tasks;
  10. using System.Windows.Forms;
  11. using System.Runtime.InteropServices;
  12.  
  13.  
  14. namespace WulaClicker
  15. {
  16. public partial class Form1 : Form
  17. {
  18. [DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
  19.  
  20. public static extern void mouse_event(uint dwFlags, uint dx, uint dy, uint cButtons, uint dwExtraInfo);
  21.  
  22. private const uint MOUSEEVENTF_LEFTDOWN = 0x02;
  23. private const uint MOUSEEVENTF_LEFTUP = 0x04;
  24. private const uint MOUSEEVENTF_RIGHTDOWN = 0x08;
  25. private const uint MOUSEEVENTF_RIGHTUP = 0x10;
  26.  
  27. public Thread autoClickerThread;
  28. public Random random = new Random();
  29. public bool recordingHotkey = false;
  30. public bool AutoClickerRunning = false;
  31. public List<Keys> KeysDown = new List<Keys>();
  32. public Keys CurrentHotkey = Keys.D9;
  33. public bool CurrentHotkey_Ctrl = true;
  34. public bool CurrentHotkey_Alt = false;
  35. public bool CurrentHotkey_Shift = true;
  36.  
  37.  
  38. /// <summary>
  39. /// Hotkey event handler
  40. /// </summary>
  41. /// <param name="sender"></param>
  42. /// <param name="e"></param>
  43. void Form_KeyDown(object sender, KeyEventArgs e)
  44. {
  45. if (recordingHotkey)
  46. {
  47. CurrentHotkey_Shift = e.Shift;
  48. CurrentHotkey_Ctrl = e.Control;
  49. CurrentHotkey_Alt = e.Alt;
  50.  
  51. KeysDown.Add(e.KeyCode);
  52. e.SuppressKeyPress = true; // Stops other controls on the form receiving event.
  53. }
  54. if (e.KeyCode == CurrentHotkey)
  55. {
  56. int quota = 3;
  57. int numFactors = 0;
  58. if (e.Alt)
  59. {
  60. if (CurrentHotkey_Alt)
  61. {
  62. numFactors++;
  63. }
  64. }
  65. else
  66. {
  67. if (!CurrentHotkey_Alt)
  68. {
  69. numFactors++;
  70. }
  71. }
  72.  
  73. if (e.Shift)
  74. {
  75. if (CurrentHotkey_Shift)
  76. {
  77. numFactors++;
  78. }
  79. }
  80. else
  81. {
  82. if (!CurrentHotkey_Shift)
  83. {
  84. numFactors++;
  85. }
  86. }
  87.  
  88. if (e.Control)
  89. {
  90. if (CurrentHotkey_Ctrl)
  91. {
  92. numFactors++;
  93. }
  94. }
  95. else
  96. {
  97. if (!CurrentHotkey_Ctrl)
  98. {
  99. numFactors++;
  100. }
  101. }
  102. if (numFactors >= quota)
  103. {
  104. if (AutoClickerRunning)
  105. {
  106. StopAutoClicker();
  107. }
  108. if (!AutoClickerRunning)
  109. {
  110. autoClickerThread = new Thread(new ThreadStart(StartAutoClicker));
  111. }
  112. }
  113. }
  114. }
  115.  
  116. void Form_KeyUp(object sender, KeyEventArgs e)
  117. {
  118. if (recordingHotkey)
  119. {
  120. CurrentHotkey_Shift = e.Shift;
  121. CurrentHotkey_Ctrl = e.Control;
  122. CurrentHotkey_Alt = e.Alt;
  123. if (!e.Shift && !e.Control && !e.Alt)
  124. {
  125. recordingHotkey = false;
  126. hotkeyButton.BackColor = Color.FromKnownColor(KnownColor.ControlLight);
  127. }
  128.  
  129. }
  130. }
  131.  
  132.  
  133. public void HotkeyButton_Click(Object sender, EventArgs e)
  134. {
  135. hotkeyButton.BackColor = Color.FromArgb(255, 128, 128);
  136. recordingHotkey = true;
  137. }
  138.  
  139. public void AboutButton_Click(Object sender, EventArgs e)
  140. {
  141. About.ShowDialog();
  142. }
  143.  
  144. public void ClickSequence(int numberOfClicks)
  145. {
  146. for (int i = 1; i <= numberOfClicks; i++)
  147. {
  148. int sleepTime = SingleClick();
  149. Thread.Sleep(sleepTime);
  150. }
  151. }
  152.  
  153. public void ClickMouse()
  154. {
  155. //Call the imported function with the cursor's current position
  156. uint X = (uint)Cursor.Position.X;
  157. uint Y = (uint)Cursor.Position.Y;
  158. mouse_event(MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP, X, Y, (uint)0, (uint)0);
  159. }
  160.  
  161. public int SingleClick()
  162. {
  163. double interval = 0.0;
  164. if (delayAfterClickBox.Checked)
  165. {
  166. ClickMouse();
  167. int min = (int)delayAfterClick_MinDelay.Value;
  168. int max = (int)delayAfterClick_MaxDelay.Value;
  169. interval = random.NextDouble() + (double)random.Next(min, max);
  170. }
  171. return (int)(interval * 1000.0);
  172. }
  173.  
  174.  
  175. public void StartAutoClicker()
  176. {
  177. AutoClickerRunning = true;
  178. BackColor = Color.FromArgb(255, 128, 128);
  179.  
  180. while (AutoClickerRunning)
  181. {
  182. int min = (int)delayAfterClicks_MinDelay.Value;
  183. int max = (int)delayAfterClicks_MaxDelay.Value;
  184.  
  185. int minC = (int)delayAfterClicks_MinClicks.Value * 1000;
  186. int maxC = (int)delayAfterClicks_MaxClicks.Value * 1000;
  187. int clix = random.Next(minC, maxC);
  188. double interval = random.NextDouble() + (double)random.Next(min, max);
  189. ClickSequence(clix);
  190. Thread.Sleep((int)(interval * 1000.0));
  191. }
  192. }
  193.  
  194. public void StopAutoClicker()
  195. {
  196. this.BackColor = Color.FromKnownColor(KnownColor.Control);
  197. AutoClickerRunning = false;
  198. }
  199.  
  200. public Form1()
  201. {
  202. InitializeComponent();
  203. }
  204. }
  205. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement