Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

How to write a bot that press everytime f1 in a another window?


horsehead
 Share

Recommended Posts

Since any macro I make would end up useing your mouse on you, there would end up being a slight freeze in your ability to use your mouse. I could make it though so that you could run the program. It switches windows and presses f1 then switches back. Would prob end up messing with less then a half second of your time if the game is not fullscreen.
Link to comment
Share on other sites

I wroote this keypress simulator a while ago (might be better methods out there, but it works :P):

it's in c#

```
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
using System.Diagnostics;
using System.Threading;

namespace Simulator
{
    class Program
    {
        const UInt32 WM_KEYDOWN = 0x0100;
        const int VK_F1 = 0x70;

        [DllImport("user32.dll")]
        static extern bool PostMessage(IntPtr hWnd, UInt32 Msg, int wParam, int lParam);

        [STAThread]

        static void Main(string[] args)
        {
            Console.Title = "Keypress Simulator";
            Console.WriteLine("Enter the name of the program you wish to send simulated keypresses to (case sensitive): ");
            string proName = Console.ReadLine();
            Console.WriteLine("start keypress simulator? (y/n)");
            string input = Console.ReadLine();
            int i = 2;
            if (input == "y")
            {
                while (true)
                {
                    Process[] processes = Process.GetProcessesByName(proName);

                    foreach (Process proc in processes)
                    {
                        PostMessage(proc.MainWindowHandle, WM_KEYDOWN, VK_F1, 0);
                    }

                    // randomize send time
                    int randomA = 10000; // milliseconds
                    int randomB = 30000; // milliseconds
                    Random rand = new Random();
                    int random;
                    random = rand.Next(randomA, randomB);
                    Thread.Sleep(random);
                    Console.WriteLine("executed at {0} ({1})", random.ToString(), i.ToString());
                    i++;
                }
            }             
        }
    }
}

```
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...