Register for your free account! | Forgot your password?

Go Back   elitepvpers > Popular Games > Silkroad Online > SRO Coding Corner
You last visited: Today at 22:09

  • Please register to post and access all features, it's quick, easy and FREE!

Advertisement



[C#] KeyPresser for non-bot server

Discussion on [C#] KeyPresser for non-bot server within the SRO Coding Corner forum part of the Silkroad Online category.

Reply
 
Old   #1
 
elite*gold: 0
Join Date: Apr 2010
Posts: 474
Received Thanks: 172
[C#] KeyPresser for non-bot server

Hi guys,

I've been developing my own keypresser for a non-bot server to auto buff chars while being AFK.

Right now it works kind of decent, and most features are implemented, however I'm running into the following problem.



As you can see on the interface above there is a worker list. I've built it so when I press the "Start" button, a thread will be created for every item in the worker list. However, it keeps happening that threads are overlapping. I've found some possible solutions, but nothing really seems to fit my problem.

The threads are set up like this:

Button_click event:
Code:
        private void btn_Start_Click(object sender, EventArgs e)
        {
            if (btn_Start.Text == "Start")
            {
                btn_Start.Text = "Stop";
                LockGUI();
                foreach(ListViewItem lvitem in lv_Worker.Items)
                {
                    string skillname = lvitem.Text;
                    int delay = Convert.ToInt32(lvitem.SubItems[1].Text);
                    delay *= 1000;
                    string targetslot = lvitem.SubItems[2].Text;
                    string bar = lvitem.SubItems[3].Text;
                    string slot = lvitem.SubItems[4].Text;
                    string targetlocation = "";
                    foreach(ListViewItem xtarget in lv_PartyLoc.Items)
                    {
                        if(xtarget.Text == targetslot)
                        {
                            targetlocation = xtarget.SubItems[1].Text;
                        }
                    }
                    string[] targetArray = targetlocation.Split(',');
                    Point targetLoc = new Point(Convert.ToInt32(targetArray[0]), Convert.ToInt32(targetArray[1]));

                    Thread tWorker = new Thread(() => DoWork(bar, slot, delay, targetLoc));
                    tWorker.Name = skillname;
                    tWorker.Start();
                    WorkerList.Add(tWorker);

                }
            }
            else
            {
                btn_Start.Text = "Start";
                UnlockGUI();
                foreach(Thread worker in WorkerList)
                {
                    worker.Abort();
                    WorkerList.Remove(worker);
                }
            }
        }
The actual worker thread code is:

Code:
 public void DoWork(string bar, string slot, int delay, Point clickloc)
        {
            Random rnd = new Random();
            int startDelay = rnd.Next(200, 9000);
            Thread.Sleep(startDelay);
            TypeConverter converter = TypeDescriptor.GetConverter(typeof(WindowsInput.Native.VirtualKeyCode));
            WindowsInput.InputSimulator Typemachine = new InputSimulator();
            VirtualKeyCode kBar = (VirtualKeyCode)converter.ConvertFromString(bar);

            int i = 0;

            do
            {
                SetCursorPos(clickloc.X, clickloc.Y);
                DoMouseClick();
                DoMouseClick();

                Typemachine.Keyboard.KeyPress(kBar);
                SendKeys.SendWait(slot);
                Thread.Sleep(delay);

            } while (i == 0);
        }
As you can see, I've built the worker thread so it uses a loop and the thread sleeps as long as the user has configured it. In the beginning I've put a random integer so the threads won't start at the same time, however this hasn't fixed my problems.

By the way, I know my coding looks like shit, but I've taught myself how to code, so I've never had a teacher.

If anyone has any tips/tricks I'd like to hear them
confict is offline  
Old 08/13/2020, 21:53   #2
 
elite*gold: 0
Join Date: Apr 2010
Posts: 474
Received Thanks: 172
Anyone?
confict is offline  
Old 08/14/2020, 09:16   #3
 
zeteris's Avatar
 
elite*gold: 0
Join Date: Jan 2009
Posts: 575
Received Thanks: 752
Hi,

One possible way of solving this is to use queue. I would suggest You have a look at

Instead of manipulating cursor/keys directly in the DoWork method You should add the work to the queue like:
Code:
Queue.Add(new Work
{
	X = clickloc.X,
	Y = clickloc.Y
	Key = kBar,
	Slot = slot
});
Then just spawn another thread which processes the work queue and actually manipulates cursor/keys:
Code:
while (true)
{
	var work = Queue.Take();
	SetCursorPos(work.X, work.Y);
	DoMouseClick();
	DoMouseClick();

	Typemachine.Keyboard.KeyPress(work.Key);
	SendKeys.SendWait(work.Slot);
}
This way You can have as many threads as You like asking to manipulate cursor/keys which will be done in another thread one after another without overlapping.

I hope this helps
zeteris is offline  
Old 08/14/2020, 12:31   #4
 
elite*gold: 0
Join Date: Apr 2010
Posts: 474
Received Thanks: 172
I'll look into this, thanks a lot @
confict is offline  
Reply


Similar Threads Similar Threads
Auto-Keypresser or Splash....Bot ???
01/26/2012 - Kal Online - 17 Replies
hi ich kenne die such funktion^^ habe sie genutzt habe nen paar bots und so nen auto-keypresser auspobiert entweder ich kam nicht mit klar oder was ofteres der fall war es ging auf ps(chillav2) net also wollte ich mal nachfragen was ich anders machen musste oder ob ihr nicht villt paar funzen dinger habt xD
[Non Stop Non Stop 24/7] For Ever Free MM Service [Non Stop 24/7]
01/10/2012 - Middleman - 38 Replies
ch möchte hier meine Dienste als Middleman anbieten. Deutsch ✔] Telefon Verifizierung ✔] Seit 3 Monaten registriert ✔] Mehr als 300 Posts ✔] Mind. 10 TBM-Bewertungen ✔] Kein negatives Rating Welchen Service biete ich an?
(Suche Silkroad Keypresser)(Need Sro Keypresser) !!
06/14/2011 - SRO Private Server - 1 Replies
Hi i search for a keypresser for silkroad i need to dlvln my char can someone help me? Suche einen keypresser für Silkroad fürs dlvln am besten auch mit autoress der geht MFG
Sunsro BOT working via script(not keypresser)
08/02/2009 - SRO Private Server - 5 Replies
SunBot wtf is that? check it out
[Request]Ecsro autopot(non keypresser)
12/02/2008 - SRO Private Server - 4 Replies
Hi, I was wondering if anyone could make an autopot wich doesnt press keys, so u dont have the anoying 9099988 etc while u are typing. I think a lot of people would find this very usefull and much appreciated. I hope someone will be able to make this, tnx in advance.



All times are GMT +1. The time now is 22:09.


Powered by vBulletin®
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2025 elitepvpers All Rights Reserved.