Laden...
J
Jeppe Düring myCSharp.de - Member
Noch Schüler Schleswig-Holstein Dabei seit 23.04.2018 1 Beiträge
Benutzerbeschreibung

Forenbeiträge von Jeppe Düring Ingesamt 1 Beiträge

23.04.2018 - 22:16 Uhr

Ich habe einen Autoklicker gemacht, um ein paar Sachen zu üben, aber seitdem ich die MetroFramework.dll als Referenz eingefügt habe und das Design geändert habe, geht der Start und Stop Button nicht mehr. Wenn mir jemand helfen kann, hier ist der Code:

using System;
using System.Threading;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Advanced_Autoclicker
{
    public partial class Autoclicker : MetroFramework.Forms.MetroForm
    {
        public int intervals { get; private set; }
        public bool threadStatus { get; private set; }

        static Thread Clicker;

        //Autoklicks
        [DllImport("user32.dll")]
        public static extern void mouse_event(int dwFlags, int dx, int dy, int cButton, int dwExtraInfo);

        public const int MOUSEEVENTF_LEFTDOWN = 0x02;
        public const int MOUSEEVENTF_LEFTUP = 0x04;

        [DllImport("user32.dll")]
        public static extern int SetCursorPos(int x, int y);


        //Radio buttons selected booleans
        public bool repeatTimes { get; private set; }
        public bool randomInterval { get; private set; }
        public bool repeatStopped;

        //Selected click options
        public string mouseButton;
        public string clickType;
        public Autoclicker()
        {
            InitializeComponent();
            comboBox1.Text = "Left";
            comboBox2.Text = "Single";
        }

        private void milliseconds_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (!char.IsControl(e.KeyChar) && !char.IsDigit(e.KeyChar))
            {
                e.Handled = true;
            }
        }

        private void textBox2_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (!char.IsControl(e.KeyChar) && !char.IsDigit(e.KeyChar))
            {
                e.Handled = true;
            }
        }

        private void minutes_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (!char.IsControl(e.KeyChar) && !char.IsDigit(e.KeyChar))
            {
                e.Handled = true;
            }
        }

        private void hours_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (!char.IsControl(e.KeyChar) && !char.IsDigit(e.KeyChar))
            {
                e.Handled = true;
            }
        }

        private void repeattimesbutton_CheckedChanged(object sender, EventArgs e)
        {
            if (repeattimesbutton.Checked)
            {
                repeatTimes = true;
            }
            else
            {
                repeatTimes = false;
            }
        }

        private void randomintervalbutton_CheckedChanged(object sender, EventArgs e)
        {
            if (randomintervalbutton.Checked)
            {
                randomInterval = true;
            }
            else
            {
                randomInterval = false;
            }
        }

        private void repeatuntilstoppedbutton_CheckedChanged(object sender, EventArgs e)
        {
            if (repeatuntilstoppedbutton.Checked)
            {
                repeatStopped = true;
            }
            else
            {
                repeatStopped = false;
            }
        }

        private void comboBox1_SelectedValueChanged(object sender, EventArgs e)
        {
            if (comboBox1.Text == "Left")
            {
                mouseButton = "Left";
            }
            else if (comboBox1.Text == "Right")
            {
                mouseButton = "Right";
            }
            else if (comboBox1.Text == "Middle")
            {
                mouseButton = "Middle";
            }
        }

        private void MouseClicker()
        {
            int i = 0;
            while (true)
            {
                Thread.Sleep(100);
                while (threadStatus)
                {
                    if (repeatTimes)
                    {
                        while (startbutton.Enabled == false)
                        {
                            int x = Cursor.Position.X;
                            int y = Cursor.Position.Y;
                            mouse_event(MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP, x, y, 0, 0);
                        }
                    }
                    else if (randomInterval)
                    {
                        while (startbutton.Enabled == false)
                        {
                            int li = Convert.ToInt32(Math.Round(lowerintervalvalue.Value, 0));
                            int hi = Convert.ToInt32(Math.Round(higherintervalvalue.Value, 0));
                            int x = Cursor.Position.X;
                            int y = Cursor.Position.Y;
                            mouse_event(MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP, x, y, 0, 0);
                            Random rand = new Random();
                            Thread.Sleep(rand.Next(li, hi));
                        }
                    }
                }
            }
        }

        private void Advanced_Autoclicker_Load(object sender, EventArgs e)
        {
            Clicker = new Thread(MouseClicker);
            Clicker.IsBackground = true;
            Clicker.Start();

            loadingBar.Value = 0;

            //themeChange.SelectedIndex = 1;
            //colorChange.SelectedIndex = 3;
        }

        private void lowerintervalvalue_KeyDown(object sender, KeyEventArgs e)
        {
            if (!(e.KeyData == Keys.Back || e.KeyData == Keys.Delete))
            {
                if (lowerintervalvalue.Text.Length >= 4)
                {
                    e.SuppressKeyPress = true;
                    e.Handled = true;
                }
                if (lowerintervalvalue.Value > 4999)
                {
                    lowerintervalvalue.Value = 4999;
                }
            }
        }

        private void higherintervalvalue_KeyDown(object sender, KeyEventArgs e)
        {
            if (!(e.KeyData == Keys.Back || e.KeyData == Keys.Delete))
            {
                if (higherintervalvalue.Text.Length >= 4)
                {
                    e.SuppressKeyPress = true;
                    e.Handled = true;
                }
                if (higherintervalvalue.Value > 5000)
                {
                    higherintervalvalue.Value = 5000;
                }
            }
        }

        private void Autoclicker_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.F9)
            {
                stopbutton.Enabled = true;
                startbutton.Enabled = false;

                //Click interval conversion
                int hourInt = (int.Parse(hours.Text) * 60 * 60 * 1000);
                int minuteInt = (int.Parse(minutes.Text) * 60 * 1000);
                int secondInt = (int.Parse(seconds.Text) * 1000);
                int millisecondInt = (int.Parse(milliseconds.Text));

                intervals = hourInt + minuteInt + secondInt + millisecondInt;

                int repeatTimesAmount = Convert.ToInt32(Math.Round(repeattimesvalue.Value, 0));


                if (repeatTimes)
                {
                    threadStatus = true;
                    Text = "Autoklicker - Klickt";
                }
                else if (randomInterval)
                {
                    threadStatus = true;
                }

                /*
                MessageBox.Show(Convert.ToString(interval));
                MessageBox.Show(mouseButton);
                MessageBox.Show(clickType);
                MessageBox.Show(repeatInterval);
                MessageBox.Show(Convert.ToString(CursorPosition()));
                */
            }
            else if (e.KeyCode == Keys.F10)
            {
                Text = "Autoklicker - Wartet auf Ausführung";
                threadStatus = false;
                startbutton.Enabled = true;
                stopbutton.Enabled = false;
            }
        }

        /*
        private void themeChange_SelectedIndexChanged(object sender, EventArgs e)
        {
            switch (themeChange.SelectedIndex)
            {
                case 0:
                    metroStyleManager1.Theme = MetroFramework.MetroThemeStyle.Light;
                    break;
                case 1:
                    metroStyleManager1.Theme = MetroFramework.MetroThemeStyle.Dark;
                    break;
            }
        }

        private void colorChange_SelectedIndexChanged(object sender, EventArgs e)
        {
            metroStyleManager1.Style = (MetroFramework.MetroColorStyle)Convert.ToInt32(colorChange.SelectedIndex);
        }
        */

        private void stopbutton_Click_1(object sender, EventArgs e)
        {
            Text = "Autoklicker - Wartet auf Ausführung";
            threadStatus = false;
            startbutton.Enabled = true;
            stopbutton.Enabled = false;
        }

        private void startbutton_Click(object sender, EventArgs e)
        {
            stopbutton.Enabled = true;
            startbutton.Enabled = false;

            //Click interval conversion
            int hourInt = (int.Parse(hours.Text) * 60 * 60 * 1000);
            int minuteInt = (int.Parse(minutes.Text) * 60 * 1000);
            int secondInt = (int.Parse(seconds.Text) * 1000);
            int millisecondInt = (int.Parse(milliseconds.Text));

            intervals = hourInt + minuteInt + secondInt + millisecondInt;

            int repeatTimesAmount = Convert.ToInt32(Math.Round(repeattimesvalue.Value, 0));


            if (repeatTimes)
            {
                threadStatus = true;
                Text = "Autoklicker - Klickt";
            }
            else if (randomInterval)
            {
                threadStatus = true;
            }

            /*
            MessageBox.Show(Convert.ToString(interval));
            MessageBox.Show(mouseButton);
            MessageBox.Show(clickType);
            MessageBox.Show(repeatInterval);
            MessageBox.Show(Convert.ToString(CursorPosition()));
            */
        }

        private void loading_Tick(object sender, EventArgs e)
        {
            if (loadingBar.Value < 100)
            {
                loadingBar.Value++;
            }
            else
            {
                loadingPanel.Visible = false;
            }
        }
    }
}

Alles im Programm funktioniert einwandfrei und es werden auch keine Fehler im Output angezeigt, aber es will irgendwie seitdem ich die MetroFramework.dll benutze und andere Button, anstatt den Standard Button, benutze, nicht mehr funktionieren. Davor hatte es einwandfrei und fehlerfrei funktioniert. Genauer kann ich hier mein Problem hier leider nicht beschreiben.
Ich nehme jede Hilfe gerne an.

MfG

Jeppe