Erreur Multiple sur un autoclicker en C# Visual Studio

Résolu
AngeDesMoutons Messages postés 9 Date d'inscription samedi 15 juin 2024 Statut Membre Dernière intervention 28 août 2024 - 15 juin 2024 à 16:52
BoBot Messages postés 3892 Date d'inscription mardi 4 juillet 2023 Statut Modérateur Dernière intervention 17 octobre 2024 - 19 juin 2024 à 18:13

Bonjour,

Cela fait pas mal de temp que j'essai de regler un beug qui me ruine tout mon programme 

Gravité    Code    Description    Projet    Fichier    Ligne    État de la suppression
Erreur (active)    CS5001    Le programme ne contient pas de méthode 'Main' statique adaptée à un point d'entrée    AutoClickerCheat    C:\Users\Utilisateur\OneDrive\Bureau\AutoClickerCheat\AutoClickerCheat\CSC    1    
 

c'est infernal je regle quelque chose cela me met une autre erreur mais pour la regler je dois revenir comme avant pourriez vous m'aidez

Voici le code :

using System;
using System.Runtime.InteropServices;
using System.Threading;
using WindowsInput;
using WindowsInput.Native;
using NHotkey;
using NHotkey.WindowsForms;
using System.Windows.Forms;
using static AutoClickerApp.GlobalKeyboardHook;
using System.Diagnostics;

namespace AutoClickerApp
{
    public partial class MainForm : Form
    {
        private bool isAutoClicking = false;
        private int cpsMin = 8; // CPS minimum
        private int cpsMax = 16; // CPS maximum
        private Random random = new Random();
        private InputSimulator inputSimulator = new InputSimulator();

        public MainForm()
        {
            InitializeComponent();

            // Enregistrement de la hotkey pour la touche `
            HotkeyManager.Current.AddOrReplace("ToggleAutoClicker", Keys.Oemtilde, ToggleAutoClicker);

            // Démarrage du hook global du clavier
            KeyboardHook.Start();
            KeyboardHook.KeyPressed += KeyboardHook_KeyPressed;

            UpdateStatusLabel();
        }

        private void ToggleAutoClicker(object sender, HotkeyEventArgs e)
        {
            isAutoClicking = !isAutoClicking;
            UpdateStatusLabel();

            if (isAutoClicking)
            {
                Thread autoClickThread = new Thread(AutoClicker);
                autoClickThread.IsBackground = true;
                autoClickThread.Start();
            }
        }

        private void AutoClicker()
        {
            while (isAutoClicking)
            {
                if (IsLeftMouseButtonDown())
                {
                    int cps = random.Next(cpsMin, cpsMax + 1); // Random CPS between cpsMin and cpsMax
                    int interval = 1000 / cps;

                    inputSimulator.Mouse.LeftButtonClick();
                    Thread.Sleep(interval);
                }
                else
                {
                    Thread.Sleep(10); // Check every 10 ms if the left mouse button is pressed
                }
            }
        }

        private void KeyboardHook_KeyPressed(object sender, KeyboardHook.KeyPressedEventArgs e)
        {
            if (e.Key == Keys.Oemtilde)
            {
                isAutoClicking = !isAutoClicking;
                UpdateStatusLabel();
            }
        }

        private void UpdateStatusLabel()
        {
            string status = isAutoClicking ? "Activé" : "Désactivé";
            lblAutoClickStatus.Text = $"Auto-clicker : {status}";
        }

        private bool IsLeftMouseButtonDown()
        {
            return (Control.MouseButtons & MouseButtons.Left) != 0;
        }

        private void trackBarCPS_Scroll(object sender, EventArgs e)
        {
            // Mettre à jour les valeurs de CPS
            cpsMin = trackBarCPS.Value - 4; // 4 est la valeur minimum du trackbar
            cpsMax = trackBarCPS.Value;
            lblCPSValue.Text = $"{cpsMin} - {cpsMax} CPS";
        }
    }

    public static class KeyboardHook
    {
        public static event EventHandler<KeyPressedEventArgs> KeyPressed;

        private static GlobalKeyboardHook _globalKeyboardHook;

        public static void Start()
        {
            _globalKeyboardHook = new GlobalKeyboardHook();
            _globalKeyboardHook.KeyboardPressed += OnKeyPressed;
        }

        private static void OnKeyPressed(object sender, GlobalKeyboardHookEventArgs e)
        {
            if (e.KeyboardData == Keys.Oemtilde && e.KeyboardState == GlobalKeyboardHook.KeyboardState.KeyDown)
            {
                KeyPressed?.Invoke(null, new KeyPressedEventArgs(Keys.Oemtilde));
            }
        }

        public class KeyPressedEventArgs : EventArgs
        {
            public Keys Key { get; private set; }

            public KeyPressedEventArgs(Keys key)
            {
                Key = key;
            }
        }
    }

    public class GlobalKeyboardHook : IDisposable
    {
        public event EventHandler<GlobalKeyboardHookEventArgs> KeyboardPressed;

        private const int WH_KEYBOARD_LL = 13;
        private const int WM_KEYDOWN = 0x0100;
        private const int WM_KEYUP = 0x0101;

        private HookProc _proc;
        private IntPtr _hookID = IntPtr.Zero;

        public GlobalKeyboardHook()
        {
            _proc = HookCallback;
            _hookID = SetHook(_proc);
        }

        public void Dispose()
        {
            UnhookWindowsHookEx(_hookID);
        }

        private IntPtr SetHook(HookProc proc)
        {
            using (Process curProcess = Process.GetCurrentProcess())
            using (ProcessModule curModule = curProcess.MainModule)
            {
                return SetWindowsHookEx(WH_KEYBOARD_LL, proc, GetModuleHandle(curModule.ModuleName), 0);
            }
        }

        private delegate IntPtr HookProc(int nCode, IntPtr wParam, IntPtr lParam);

        private IntPtr HookCallback(int nCode, IntPtr wParam, IntPtr lParam)
        {
            if (nCode >= 0 && (wParam == (IntPtr)WM_KEYDOWN || wParam == (IntPtr)WM_KEYUP))
            {
                int vkCode = Marshal.ReadInt32(lParam);
                Keys key = (Keys)vkCode;

                KeyboardState state = wParam == (IntPtr)WM_KEYDOWN ? KeyboardState.KeyDown : KeyboardState.KeyUp;

                KeyboardPressed?.Invoke(this, new GlobalKeyboardHookEventArgs(key, state));
            }
            return CallNextHookEx(_hookID, nCode, wParam, lParam);
        }

        public enum KeyboardState
        {
            KeyDown,
            KeyUp
        }

        public class GlobalKeyboardHookEventArgs : EventArgs
        {
            public Keys KeyboardData { get; private set; }
            public KeyboardState KeyboardState { get; private set; }

            public GlobalKeyboardHookEventArgs(Keys keyboardData, KeyboardState keyboardState)
            {
                KeyboardData = keyboardData;
                KeyboardState = keyboardState;
            }
        }

        [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
        private static extern IntPtr SetWindowsHookEx(int idHook, HookProc lpfn, IntPtr hMod, uint dwThreadId);

        [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
        [return: MarshalAs(UnmanagedType.Bool)]
        private static extern bool UnhookWindowsHookEx(IntPtr hhk);

        [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
        private static extern IntPtr CallNextHookEx(IntPtr hhk, int nCode, IntPtr wParam, IntPtr lParam);

        [DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
        private static extern IntPtr GetModuleHandle(string lpModuleName);
    }
}


Windows / Chrome 125.0.0.0

A voir également:

2 réponses

Utilisateur anonyme
Modifié le 17 juin 2024 à 19:21

Bonjour

ben le message est clair non ?

Tu n'as pas défini ou plutôt, tu as supprimé (parce que quand on crée un projet avec VS, il te le configure) le point d'entrée.

Si y'a pas de point d'entrée, Windows ne sait pas par quoi commencer dans ton programme.


0
BoBot Messages postés 3892 Date d'inscription mardi 4 juillet 2023 Statut Modérateur Dernière intervention 17 octobre 2024 245
19 juin 2024 à 18:13
Bonjour !
L'IA de Bobot est là pour vous aider !
L'erreur CS5001 indique qu'il n'y a pas de méthode Main () dans votre programme, qui est le point d'entrée de l'application. Chaque application C# doit avoir une méthode Main (). Pour ce genre de projet (application Windows Form), le point d'entrée est généralement caché dans le code généré automatiquement par l'IDE et il n'est pas nécessaire de le fournir explicitement. Cependant, si pour une raison quelconque il manque, cela peut causer ce genre d'erreurs.

Assurez-vous que vous avez bien choisi le type de votre projet lors de sa création. Pour un autoclicker, cela devrait être une "Application Windows Forms".

Si vous avez bien indiqué lors de la création du projet qu'il s'agissait d'une application Windows Forms, alors le problème pourrait être dû à un réglage de l'IDE. Dans ce cas, allez dans les propriétés du projet, et vérifiez que "Type de sortie" est réglé sur "Application Windows".

Ajoutez un point d'entrée au projet si ces étapes ne résolvent pas le problème.

Créez une nouvelle classe avec la méthode Main comme ceci :

```
static class Program
{
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new MainForm());
}
}
```

La méthode Main crée une instance de MainForm et commence à l'exécuter. C'est le point d'entrée standard pour une application Windows Forms.


0