-2

I'm trying to create a simple automated key presser. It works fine on notepad, etc. but it does not work in the game window.

Do you have any idea ?

namespace PoyBot
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            this.TopMost = true;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            timer1.Start();
            //timer2.Start();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            timer1.Stop();
            //timer2.Stop();
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            if (checkBox1.Checked)
            {
                SendKeys.SendWait("z7");
            }
            else if (checkBox2.Checked)
            {
                SendKeys.Send("z8");
            }
        }

        private void timer2_Tick(object sender, EventArgs e)
        {
            if (checkBox3.Checked)
            {
                SendKeys.Send("0");
            }
        }
    }
}
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459

1 Answers1

-1

'nameOfYourWindow' you can find uses spyxx.exe or with

[DllImport("user32.dll")]
internal static extern IntPtr GetForegroundWindow();

After you can find hwnd of your window and send button presses

IntPtr hWND = FindWindow(null, nameOfYourWindow);

PostMessage(hWND, 0x0100, (int)Keys.Tab, 0);
Thread.Sleep(30);
PostMessage(hWND, 0x0101, (int)Keys.Tab, 0);