2018-07-07 15:03:45 +02:00
|
|
|
|
using System;
|
2019-04-23 15:14:09 +02:00
|
|
|
|
using System.Diagnostics;
|
2018-07-07 15:03:45 +02:00
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
using System.Runtime.InteropServices;
|
2019-04-23 15:14:09 +02:00
|
|
|
|
using System.Drawing;
|
2019-11-10 00:28:55 +01:00
|
|
|
|
using System.Threading;
|
2018-07-07 15:03:45 +02:00
|
|
|
|
|
2019-04-23 15:14:09 +02:00
|
|
|
|
#pragma warning disable IDE1006
|
|
|
|
|
namespace CC_Clicker_2._0
|
2018-07-07 15:03:45 +02:00
|
|
|
|
{
|
2019-11-10 00:28:55 +01:00
|
|
|
|
public partial class MainForm : Form
|
2018-07-07 15:03:45 +02:00
|
|
|
|
{
|
2019-11-10 00:28:55 +01:00
|
|
|
|
Point loc = Point.Empty;
|
2019-11-11 13:35:39 +01:00
|
|
|
|
readonly OvPForm ov;
|
2019-11-10 12:13:07 +01:00
|
|
|
|
public static Button _keyButton;
|
|
|
|
|
public static bool _isSettingKey = false;
|
|
|
|
|
public static Keys _key = Keys.LShiftKey;
|
|
|
|
|
public static bool _isClicking = false;
|
|
|
|
|
public static int _setDelay = 100;
|
|
|
|
|
public static int _delmVal = 4;
|
|
|
|
|
public static CheckBox _clickBox;
|
2019-11-10 00:28:55 +01:00
|
|
|
|
public MainForm()
|
2018-07-07 15:03:45 +02:00
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
2019-11-10 12:13:07 +01:00
|
|
|
|
_keyButton = keyButton;
|
|
|
|
|
_clickBox = clickBox;
|
2019-11-10 00:28:55 +01:00
|
|
|
|
ov = new OvPForm(loc.X, loc.Y);
|
2018-07-07 15:03:45 +02:00
|
|
|
|
}
|
|
|
|
|
|
2019-04-23 15:14:09 +02:00
|
|
|
|
public static IntPtr HookCallback(int nCode, IntPtr wParam, IntPtr lParam)
|
2018-07-07 15:03:45 +02:00
|
|
|
|
{
|
2019-04-23 15:14:09 +02:00
|
|
|
|
if (nCode >= 0 && wParam == (IntPtr)WM_KEYDOWN)
|
|
|
|
|
{
|
|
|
|
|
int vkCode = Marshal.ReadInt32(lParam);
|
2019-11-10 12:13:07 +01:00
|
|
|
|
if (_isSettingKey)
|
2019-04-23 15:14:09 +02:00
|
|
|
|
{
|
2019-11-10 12:13:07 +01:00
|
|
|
|
_key = (Keys)vkCode;
|
|
|
|
|
_keyButton.BackColor = Color.FromArgb(224, 224, 224);
|
|
|
|
|
_clickBox.Enabled = true;
|
|
|
|
|
_keyButton.Text = ((Keys)vkCode).ToString();
|
|
|
|
|
_isSettingKey = false;
|
2019-04-23 15:14:09 +02:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2019-11-10 12:13:07 +01:00
|
|
|
|
if ((Keys)vkCode == _key)
|
|
|
|
|
_isClicking = !_isClicking;
|
2019-04-23 15:14:09 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return CallNextHookEx(_hookID, nCode, wParam, lParam);
|
2018-07-07 15:03:45 +02:00
|
|
|
|
}
|
|
|
|
|
|
2019-04-23 15:14:09 +02:00
|
|
|
|
private void clickBox_CheckedChanged(object sender, EventArgs e)
|
2018-07-07 15:03:45 +02:00
|
|
|
|
{
|
2019-11-10 12:13:07 +01:00
|
|
|
|
_isClicking = false;
|
2019-11-10 00:28:55 +01:00
|
|
|
|
timer.Enabled = clickBox.Checked;
|
2018-07-07 15:03:45 +02:00
|
|
|
|
}
|
|
|
|
|
|
2019-11-10 12:13:07 +01:00
|
|
|
|
private void timeBox_TextChanged(object sender, EventArgs e)
|
2018-07-07 15:03:45 +02:00
|
|
|
|
{
|
2019-04-23 15:14:09 +02:00
|
|
|
|
if (int.TryParse(timeBox.Text, out int re) && re > 0)
|
|
|
|
|
{
|
2019-11-10 12:13:07 +01:00
|
|
|
|
_setDelay = re;
|
2019-11-10 00:28:55 +01:00
|
|
|
|
timer.Interval = re;
|
2019-04-23 15:14:09 +02:00
|
|
|
|
timeBox.BackColor = Color.White;
|
2019-11-10 00:28:55 +01:00
|
|
|
|
}
|
|
|
|
|
else
|
2019-04-23 15:14:09 +02:00
|
|
|
|
{
|
|
|
|
|
timeBox.BackColor = Color.Red;
|
|
|
|
|
}
|
2018-07-07 15:03:45 +02:00
|
|
|
|
}
|
|
|
|
|
|
2019-04-23 15:14:09 +02:00
|
|
|
|
private void delmVal_TextChanged(object sender, EventArgs e)
|
2018-07-07 15:03:45 +02:00
|
|
|
|
{
|
2019-04-23 15:14:09 +02:00
|
|
|
|
if (int.TryParse(delmVal.Text, out int re) && re > 0 && re % 2 == 0)
|
|
|
|
|
{
|
2019-11-10 12:13:07 +01:00
|
|
|
|
_delmVal = re;
|
2019-04-23 15:14:09 +02:00
|
|
|
|
delmVal.BackColor = Color.White;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
delmVal.BackColor = Color.Red;
|
|
|
|
|
}
|
2018-07-07 15:03:45 +02:00
|
|
|
|
}
|
|
|
|
|
|
2019-04-23 15:14:09 +02:00
|
|
|
|
private void keyButton_Click(object sender, EventArgs e)
|
2018-07-07 15:03:45 +02:00
|
|
|
|
{
|
2019-11-10 12:13:07 +01:00
|
|
|
|
_isSettingKey = true;
|
2019-04-23 15:14:09 +02:00
|
|
|
|
keyButton.BackColor = Color.FromArgb(128, 255, 128);
|
|
|
|
|
}
|
|
|
|
|
|
2019-11-10 12:13:07 +01:00
|
|
|
|
private void timer_Tick(object sender, EventArgs e)
|
2019-04-23 15:14:09 +02:00
|
|
|
|
{
|
2019-11-10 12:13:07 +01:00
|
|
|
|
if (_isClicking)
|
2019-11-10 00:28:55 +01:00
|
|
|
|
{
|
2019-11-10 12:13:07 +01:00
|
|
|
|
if (fixBox.Checked)
|
|
|
|
|
Cursor.Position = loc;
|
|
|
|
|
mouse_event((uint)(rightBox.Checked ? (MOUSEEVENTF_RIGHTDOWN | MOUSEEVENTF_RIGHTUP) : (MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP)), (uint)Cursor.Position.X, (uint)Cursor.Position.Y, 0, 0);
|
2019-11-10 00:28:55 +01:00
|
|
|
|
if (delmBox.Checked)
|
2019-11-10 12:13:07 +01:00
|
|
|
|
timer.Interval = Math.Max(_setDelay + (new Random().Next(0, _delmVal) - (_delmVal / 2)), 1);
|
2019-11-10 00:28:55 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void fixButton_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
ov.Hide();
|
2019-11-11 13:35:39 +01:00
|
|
|
|
using (LocForm frm = new LocForm())
|
2019-11-10 00:28:55 +01:00
|
|
|
|
{
|
2019-11-11 13:35:39 +01:00
|
|
|
|
if (frm.ShowDialog() == DialogResult.OK)
|
|
|
|
|
{
|
|
|
|
|
loc = new Point(frm.X, frm.Y);
|
|
|
|
|
fixBox.Checked = true;
|
|
|
|
|
fixButton.BackColor = Color.Green;
|
|
|
|
|
fixButton.Text = loc.ToString();
|
|
|
|
|
}
|
2019-11-10 00:28:55 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void fixBox_CheckedChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (loc == Point.Empty)
|
|
|
|
|
{
|
|
|
|
|
fixBox.Checked = false;
|
|
|
|
|
fixButton.BackColor = Color.Red;
|
2018-07-07 15:03:45 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-11-10 00:28:55 +01:00
|
|
|
|
private void fixButton_MouseEnter(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
ov.setPos(loc.X, loc.Y);
|
|
|
|
|
ov.Show();
|
|
|
|
|
}
|
2019-04-23 15:14:09 +02:00
|
|
|
|
|
2019-11-10 00:28:55 +01:00
|
|
|
|
private void fixButton_MouseLeave(object sender, EventArgs e) => ov.Hide();
|
|
|
|
|
#region DllImports
|
2019-04-23 15:14:09 +02:00
|
|
|
|
[DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
|
2019-11-10 00:28:55 +01:00
|
|
|
|
static extern void mouse_event(uint dwFlags, uint dx, uint dy, uint cButtons, uint dwExtraInfo);
|
2019-04-23 15:14:09 +02:00
|
|
|
|
public const int MOUSEEVENTF_LEFTDOWN = 0x02;
|
|
|
|
|
public const int MOUSEEVENTF_LEFTUP = 0x04;
|
|
|
|
|
public const int MOUSEEVENTF_RIGHTDOWN = 0x08;
|
|
|
|
|
public const int MOUSEEVENTF_RIGHTUP = 0x10;
|
|
|
|
|
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
|
2019-11-10 00:28:55 +01:00
|
|
|
|
static extern IntPtr SetWindowsHookEx(int idHook, LowLevelKeyboardProc lpfn, IntPtr hMod, uint dwThreadId);
|
2019-04-23 15:14:09 +02:00
|
|
|
|
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
|
2019-11-10 00:28:55 +01:00
|
|
|
|
static extern IntPtr CallNextHookEx(IntPtr hhk, int nCode, IntPtr wParam, IntPtr lParam);
|
|
|
|
|
[DllImport("kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
|
|
|
|
|
static extern IntPtr GetModuleHandle(string lpModuleName);
|
2019-04-23 15:14:09 +02:00
|
|
|
|
public static IntPtr SetHook(LowLevelKeyboardProc proc)
|
2018-07-07 15:03:45 +02:00
|
|
|
|
{
|
2019-04-23 15:14:09 +02:00
|
|
|
|
using (Process curProcess = Process.GetCurrentProcess())
|
|
|
|
|
using (ProcessModule curModule = curProcess.MainModule)
|
2018-07-07 15:03:45 +02:00
|
|
|
|
{
|
2019-04-23 15:14:09 +02:00
|
|
|
|
return SetWindowsHookEx(WH_KEYBOARD_LL, proc, GetModuleHandle(curModule.ModuleName), 0);
|
2018-07-07 15:03:45 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
2019-04-23 15:14:09 +02:00
|
|
|
|
|
|
|
|
|
public delegate IntPtr LowLevelKeyboardProc(int nCode, IntPtr wParam, IntPtr lParam);
|
2019-11-10 00:28:55 +01:00
|
|
|
|
const int WH_KEYBOARD_LL = 13;
|
|
|
|
|
const int WM_KEYDOWN = 0x0100;
|
2019-04-23 15:14:09 +02:00
|
|
|
|
public static LowLevelKeyboardProc _proc = HookCallback;
|
|
|
|
|
public static IntPtr _hookID = IntPtr.Zero;
|
|
|
|
|
#endregion
|
2018-07-07 15:03:45 +02:00
|
|
|
|
}
|
|
|
|
|
}
|