sendkeys to combat arms

Posts 1–8 of 8 · Page 1 of 1
sendkeys to combat arms
so everyone says that you cant use sendkeys on combat arms... well i beg to differ.
i have a 100% working method of sending keypress to combat arms window
so the reason for creating this post is...? o.O
Quote Originally Posted by sorpz View Post
so the reason for creating this post is...? o.O
well everyone says it doesnt work.. but if you grab the window handle then send it to that.. it works...
Would you mind telling everyone which Windows API you're using? PostMessage(), SendInput()? Obviously just not SendKeys.Send.

keybd_event would also probably work, but then you're forced to keep the application active. (probably unlike your solution..?)
Quote Originally Posted by abuckau907 View Post
Would you mind telling everyone which Windows API you're using? PostMessage(), SendInput()? Obviously just not SendKeys.Send.

keybd_event would also probably work, but then you're forced to keep the application active. (probably unlike your solution..?)
well i started to go one direction. but i ended up switching. if you want to clean it up you can....
but it works :P
Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Diagnostics;
using System.Threading;
namespace macro2
{
    public partial class Form1 : Form
    {
        [DllImport("user32.dll")]
        static extern bool PostMessage(IntPtr hWnd, UInt32 Msg, int wParam, int lParam);
        [DllImport("user32.dll")]
        public static extern int SetForegroundWindow(IntPtr hWnd);
        [DllImport("user32.dll", SetLastError = true)]
        static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
        public Form1()
        {
            InitializeComponent();
            MessageBox.Show("Welcome to speed's AFK Bot V1.0");

        }
        private void perplexButton1_Click(object sender, EventArgs e)
        {
            F5.Start();
            Enter.Start();
            ESC.Start();
            IntPtr hWnd = FindWindow(null, "Combat Arms");
                     SetForegroundWindow(hWnd);
        }
        private void perplexButton2_Click(object sender, EventArgs e)
        {
            F5.Stop();
            Enter.Stop();
            ESC.Stop();
        }
        private void perplexCheckBox1_CheckedChanged(object sender, EventArgs e)
        {
            Application.Exit();
        }
        private void Enter_Tick(object sender, EventArgs e)
        {
            SendKeys.Send("{ENTER}");
            SendKeys.Send("{ESC}");
            SendKeys.Send("{F5}");
        }
    }
}
Quote Originally Posted by iamspeedforyou View Post
well i started to go one direction. but i ended up switching. if you want to clean it up you can....
but it works :P
Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Diagnostics;
using System.Threading;
namespace macro2
{
    public partial class Form1 : Form
    {
        [DllImport("user32.dll")]
        static extern bool PostMessage(IntPtr hWnd, UInt32 Msg, int wParam, int lParam);
        [DllImport("user32.dll")]
        public static extern int SetForegroundWindow(IntPtr hWnd);
        [DllImport("user32.dll", SetLastError = true)]
        static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
        public Form1()
        {
            InitializeComponent();
            MessageBox.Show("Welcome to speed's AFK Bot V1.0");

        }
        private void perplexButton1_Click(object sender, EventArgs e)
        {
            F5.Start();
            Enter.Start();
            ESC.Start();
            IntPtr hWnd = FindWindow(null, "Combat Arms");
                     SetForegroundWindow(hWnd);
        }
        private void perplexButton2_Click(object sender, EventArgs e)
        {
            F5.Stop();
            Enter.Stop();
            ESC.Stop();
        }
        private void perplexCheckBox1_CheckedChanged(object sender, EventArgs e)
        {
            Application.Exit();
        }
        private void Enter_Tick(object sender, EventArgs e)
        {
            SendKeys.Send("{ENTER}");
            SendKeys.Send("{ESC}");
            SendKeys.Send("{F5}");
        }
    }
}
Ehhhhhh.. why including api if not using anywhere? oO >> PostMessage() ... <- Ahh nvm.. sri

And could you exactly explain how to use SendKeys.Send() for a window handle?
It just sends input keys to the foreground window.. you can't use it on a specified window handle if not foreground... maybe you ment using the handle setting its window to foreground and then sending keys... please keep clean explaining your solution...
Quote Originally Posted by sorpz View Post
It just sends input keys to the foreground window.. you can't use it on a specified window handle if not foreground... maybe you ment using the handle setting its window to foreground and then sending keys
IntPtr hWnd = FindWindow(null, "Combat Arms");
SetForegroundWindow(hWnd);
is that not what this does
My 2 cents;

Code:
 [DllImport("User32.dll", CharSet = CharSet.None)]
  public static extern int PostMessage(IntPtr hWnd, int Msg, int wParam, int lParam);

  public const int WM_KEYDOWN = 256;
  public const int WM_KEYUP = 257;

  public static void SendKey(IntPtr hWnd, Keys key)
  {
       PostMessage(hWnd, 256, (int) key, 0);
       PostMessage(hWnd, 257, (int) key, 1);
  }
and example for use
Code:
Process[] Proceses = Proceses.GetProcesesByName("ProcessToget")
IntPtr hWnd=Proceses.GetProcessById(Proceses[1].Id).MainWindowHandle;

SendKey(hWnd, Keys.P) //Sends P key to 1-first window handle
Posts 1–8 of 8 · Page 1 of 1

Post a Reply

Similar Threads

Tags for this Thread

None

Talk with us