This repository has been archived on 2022-08-05. You can view files and clone it, but cannot push or open issues or pull requests.
CC-Clicker/CC-Clicker 2.0/MainForm.cs

116 lines
3.5 KiB
C#
Raw Normal View History

2018-07-07 15:03:45 +02:00
using System;
2019-04-23 15:14:09 +02:00
using System.Drawing;
2020-03-11 18:53:32 +01:00
using System.Windows.Forms;
using CC_Functions.W32;
using CC_Functions.W32.Hooks;
2018-07-07 15:03:45 +02:00
2019-04-23 15:14:09 +02:00
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
{
2020-03-11 18:53:32 +01:00
private static bool _isSettingKey;
private const Keys Key = Keys.LShiftKey;
private static bool _isClicking;
private static int _setDelay = 100;
private static int _delmVal = 4;
private readonly OvPForm _ov;
private Point _loc = Point.Empty;
2018-07-07 15:03:45 +02:00
2020-03-11 18:53:32 +01:00
public MainForm(KeyboardHook hook)
2018-07-07 15:03:45 +02:00
{
2020-03-11 18:53:32 +01:00
InitializeComponent();
Button keyButton1 = keyButton;
_ov = new OvPForm(_loc.X, _loc.Y);
hook.OnKeyPress += (e) =>
2019-04-23 15:14:09 +02:00
{
2019-11-10 12:13:07 +01:00
if (_isSettingKey)
2019-04-23 15:14:09 +02:00
{
2020-03-11 18:53:32 +01:00
keyButton1.BackColor = Color.FromArgb(224, 224, 224);
clickBox.Enabled = true;
keyButton1.Text = e.Key.ToString();
2019-11-10 12:13:07 +01:00
_isSettingKey = false;
2019-04-23 15:14:09 +02:00
}
else
{
2020-03-11 18:53:32 +01:00
if (e.Key == Key)
2019-11-10 12:13:07 +01:00
_isClicking = !_isClicking;
2019-04-23 15:14:09 +02:00
}
2020-03-11 18:53:32 +01:00
};
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
{
2020-03-11 18:53:32 +01:00
if (!_isClicking) return;
if (fixBox.Checked)
Cursor.Position = _loc;
Mouse.Click(rightBox.Checked);
if (delmBox.Checked)
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)
{
2020-03-11 18:53:32 +01:00
_ov.Hide();
using LocForm frm = new LocForm();
if (frm.ShowDialog() != DialogResult.OK) return;
_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)
{
2020-03-11 18:53:32 +01:00
if (_loc != Point.Empty) return;
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)
{
2020-03-11 18:53:32 +01:00
_ov.SetPos(_loc.X, _loc.Y);
_ov.Show();
2018-07-07 15:03:45 +02:00
}
2019-04-23 15:14:09 +02:00
2020-03-11 18:53:32 +01:00
private void fixButton_MouseLeave(object sender, EventArgs e) => _ov.Hide();
2018-07-07 15:03:45 +02:00
}
2020-03-11 18:53:32 +01:00
}