My autoclicker project is not working.

I will attach the codes I am using for the autoclicker so you can check and review, there is no error when compiling. It is simply that when I have it compiled it does not set coordinates and therefore it does not activate either. I have 2 Timers added, Timer 2 is in Enabled True.
76 Replies
Buddy
Buddy4w ago
Autoclicker for what?
Unknown User
Unknown User4w ago
Message Not Public
Sign In & Join Server To View
シュナイダー
It's for a game, yes, but as I said, the code isn't working for me. ¯\_(ツ)_/¯
Unknown User
Unknown User4w ago
Message Not Public
Sign In & Join Server To View
シュナイダー
Can you help me pls?
Unknown User
Unknown User4w ago
Message Not Public
Sign In & Join Server To View
シュナイダー
The code is correct, but it doesn't work for me. It doesn't set coordinates when I use the key and therefore nothing works
Unknown User
Unknown User4w ago
Message Not Public
Sign In & Join Server To View
Dinosaure
Dinosaure4w ago
@シュナイダー May you share the InitializeComponent implementation? I think what's missing is the event linking to the timer1_Tick function:
//
// timer1
//
timer1.Enabled = true;
timer1.Tick += timer1_Tick;
//
// timer2
//
timer2.Tick += timer2_Tick;
//
// timer1
//
timer1.Enabled = true;
timer1.Tick += timer1_Tick;
//
// timer2
//
timer2.Tick += timer2_Tick;
With this, your project does work in my end, but beware: the cursor is flashing and goes to top-left, so you should add an escape route, or comment out the Cursor.Position actually moving the mouse while debugging. This should work out of the box, maybe. Hope it'll help.
シュナイダー
I just saw your messages, I didn't understand what you mean by sharing InitializeComponent I added the line: using Timer = System.Windows.Forms.Timer; but it had no effect.
Dinosaure
Dinosaure4w ago
Have you somewhere the line timer1.Tick += timer1_Tick; in your code base?
シュナイダー
Not as far as I know, but above the post you can see the .txt that I attached with all the code in case you want to review it. I wrote the code for the entire project based on a YouTube video tutorial and in the video the person is seeing the autoclicker working, but it is true that in the comments I have found people with the same problem as me despite having done everything exactly the same...
Dinosaure
Dinosaure4w ago
I've attached a modified version with the missing InitializeComponent method. You should click on your timer, go to events, then set the Tick event to be timer1_Tick.
No description
シュナイダー
Should I change timer1 to timer1_tick?
Dinosaure
Dinosaure4w ago
No, hmm. I'll make a gif for you.
シュナイダー
This comes just like I showed you.
Dinosaure
Dinosaure4w ago
If this is already done, can you share the Form1.Designer.cs file?
No description
Dinosaure
Dinosaure4w ago
(Revised edition) This should work out of the box, maybe. Hope it'll help.
シュナイダー
I have an interface query, why does the textbox look so bad here unlike in VS?
No description
シュナイダー
If you look closely, a kind of blue line appears, while in the other one it is not. And in the VS it looks like this:
Dinosaure
Dinosaure4w ago
It's the "focused" style.
シュナイダー
(?) Oh I get it, when I select one and the other they turn blue. Now I'm going to put the project code that you sent, because in the end I decided to start a new project.
Dinosaure
Dinosaure4w ago
If you want to share here your current .designer.cs file you had, I can merge that with the one I provided before. Otherwise, you can already get the one I've sent by clicking the "download" button on the bottom, and apply it to your project. You don't need to start a new project: just rename your current Form as Form2, or alike, and get the one shared here.
シュナイダー
So this .txt code doesn't work? I say this because it's from a video tutorial
Dinosaure
Dinosaure4w ago
The one you put in OP was missing a key element, the InitializeComponent implementation (usually found in a Form.Designer.cs file) that would link the event to the actual method call.
シュナイダー
I don't really understand... so, should I create a designer.cs or drag the one you sent me to VS?
Dinosaure
Dinosaure4w ago
I think the base question I should have asked is which .Net version are you coding in?
シュナイダー
4.8
Dinosaure
Dinosaure4w ago
Oh. Let me tweak some code lines here and there.
シュナイダー
Since you're here, can I send you the link to the video? Because it works for the guy in the video and it doesn't for me, despite posting line by line. The video is many years old but I think it should still be worth it.
Dinosaure
Dinosaure4w ago
4.8 version (just had to get the namespace back to basic block) How to use: - Download this - Put it as Form1.cs file in your project - Remove the Form1.Designer.cs file - Compile & Run .
シュナイダー
That's the video tutorial I wanted to show you. Although I don't understand why you have to do that, replacing one Form1.cs with another...
Dinosaure
Dinosaure4w ago
Solely because mine has the initializeComponent mixed in in the main file, not as a separate designer one. It should work roughly same.
シュナイダー
And this is going to keep happening to me every time I want to do something...?
シュナイダー
Which of these are you saying to delete? Form1 is where I have the interface and such...
No description
Dinosaure
Dinosaure4w ago
Ìf you followed only the video tutorial, you should delete none of those files. If you downloaded the file I shared, you can remove Form1.Designer.cs.
シュナイダー
So if I followed the tutorial in the video I sent you, what should I do then? Because the code has no errors, timer1 is set to enabled false and timer2 is set to enabled true, and each code is set where it corresponds.
Dinosaure
Dinosaure4w ago
At the 6:49 mark, it's written in plain text (but displayed briefly in motion at 6:58) that you have to double click on timer1 from the form Designer to have it generate the event binding, then fill it with the code. If you've done that, you should have a working code You may want the timer1 Enabled to be set to true to have those displays working.
シュナイダー
I'm seeing it now... how stupid of me.
Dinosaure
Dinosaure4w ago
Not a problem!
シュナイダー
I kept double clicking on timer1 and copying the code that was in timer2, damn it.
Dinosaure
Dinosaure4w ago
Is your autoclicker project working now?
シュナイダー
No wait, if I did it 100% like in the video, I still don't understand. Nope :/ Also in timer1 is where mouse_event goes, if I put enabled true there as soon as I open the project it will already be clicking like crazy, therefore it must be enabled false, and timer2 where the keys go to set coordinates, activate and deactivate autoclick enabled so that technically I press them and they work but it is not doing so. And now I thought I was wrong but no, everything is as it should be.
Dinosaure
Dinosaure4w ago
Oh, that's timer2 that is supposed to enable timer1, I see. Have you tried to go with a minimalistic version, where you actually have a debugger line enabled, and step-by-step break down into the code?
シュナイダー
Mmmm no .-.
Dinosaure
Dinosaure4w ago
Just go in the timer2_Tick function block, and press F9, then run the project. If Timer2 is ok, you'll hit the debugger, and you may go F10 to get one line at a time. 🙂
シュナイダー
Which line should it be on?
No description
Dinosaure
Dinosaure4w ago
This is ok as it is: your timer2 does tick, so your project is likely to be working. You can actually remove the break point (press F9 again on the same line), then F5 to resume run flow, and use the project as intended.
シュナイダー
But it still doesn't give me coordinates... I press F3 where technically the numbers should be displayed in the textbox and that doesn't happen...
Dinosaure
Dinosaure4w ago
That’s not a technical topic anymore, but I will try to help with the use case.
シュナイダー
The autoclicker still doesn't work, I can't set coordinates, much less activate and deactivate it.
Dinosaure
Dinosaure4w ago
It looks like GetAsyncKeyState isn’t triggering on key presses.
シュナイダー
And there is no error in the code because at least VS is not marking anything for me...
Dinosaure
Dinosaure4w ago
Found the problem: you have to replace -32767 by 32769. It looks like 32bits code isn’t working in 64bits environment here!
シュナイダー
Guess what... it still doesn't work.😂
Dinosaure
Dinosaure4w ago
That’s the key_down state value. If you set it to the expected 32769, you may press F8 to gather mouse position, then F2 to actually trigger on/off timer1 state. The actual trigger for timer1 is shit tho, you may prefer to not trigger+release in the same F2 call. 🙃
シュナイダー
So...
Dinosaure
Dinosaure4w ago
You may prefer this for your timer2_Tick function:
private void timer2_Tick(object sender, EventArgs e)
{
if (GetAsyncKeyState(Keys.F8) == 32769)
{
GetCursorPos(out Point cursor);
(xPos, yPos) = (cursor.X, cursor.Y);
(textBox1.Text, textBox2.Text) = (xPos.ToString(), yPos.ToString());
}

if (GetAsyncKeyState(Keys.F2) == 32769)
{
timer1.Interval = Convert.ToInt32(numericUpDown1.Value);
timer1.Enabled = !timer1.Enabled;
}
}
private void timer2_Tick(object sender, EventArgs e)
{
if (GetAsyncKeyState(Keys.F8) == 32769)
{
GetCursorPos(out Point cursor);
(xPos, yPos) = (cursor.X, cursor.Y);
(textBox1.Text, textBox2.Text) = (xPos.ToString(), yPos.ToString());
}

if (GetAsyncKeyState(Keys.F2) == 32769)
{
timer1.Interval = Convert.ToInt32(numericUpDown1.Value);
timer1.Enabled = !timer1.Enabled;
}
}
シュナイダー
I finally got it by asking chatgpt, check this out if ((GetAsyncKeyState(Keys.F1) & 0x8000) != 0) Awesome...
Dinosaure
Dinosaure4w ago
Beware that a release state is 1, so you're at risk to trigger the call both by press then release.
シュナイダー
What does that mean?
Dinosaure
Dinosaure4w ago
When you press a key, the GetAsyncKeyState returns a value depending on the last event: Either it's pressed (32769), or released (1), or none (0).
シュナイダー
I can't understand but oh well... now I have another question, now that the autoclicker FINALLY works, is there any way I can have my physical cursor free and the virtual cursor, let's say, the one that is going to click in the set position, can stay there and not bother the real cursor? 👀
Dinosaure
Dinosaure4w ago
There has to be a way, since you can send messages to windows or processes, and having them virtual clicks not triggered by your real cursor position. How you would do that here is beyond my scope, since I use AutoIt when I have to do that: it's as simple as ControlClick("Target window title", "optional field", 0, "primary", 1, X, Y), where 0 is the target controlID, and X and Y mouse coordinates. It's something down the window message pipe, but it could be a little off the ground for now. 🙂
シュナイダー
Technically, this code does the job, but I think Windows 11 is interfering because sometimes I can move the cursor and click but it returns to the position where the coordinates were set...
Dinosaure
Dinosaure4w ago
You should have a look (and try to fully understand) what the timer1_Tick function does, line by line. It will help you understand the mouse movements.
シュナイダー
If I understand what I understand, it's basically creating a new point, and trying to bring the cursor to the position where it is fixed, but the thing is that I want the clicks to occur where I manually set with the "real" cursor while the "virtual" or "fictional" or "ghost" cursor clicks in the fixed position while my "real" cursor is totally free and I can move it and give manual clicks...
Dinosaure
Dinosaure4w ago
I think I understand your desired use case, but I don't have the knowledge yet to get you a satisfying answer. Non-satisfying answer tho: you may have a look at SendInput from the user32 api. Your best bet is to ask Copilot about it, maybe you will have more satisfaction!
シュナイダー
Ok, I try. Thanks for all ❤️
Dinosaure
Dinosaure4w ago
I prompted "How to use the SendInput function from the user32's API to simulate mouse clicks?" and it got me a bunch of code that looks legit.
シュナイダー
Nice.
Want results from more Discord servers?
Add your server