Jump to content

Photo

Clicking without window being active


  • Please log in to reply
No replies to this topic

#1 Papa Beans Posted 06 April 2015 - 04:16 AM

Papa Beans

    Soldier

  • Members
  • Pip
  • 1 posts

Hello!

 

  I really hope this project isn't dead, as it is exactly what I was looking for. I've always wanted to make a program that can automate clicks and keyboard strokes in in the background, and I'm pretty sure I can do it with this. I'll give a rundown of what I have / have tried.

 

 

Reading over another post, the main dev suggested that he use SendMessage. That doesn't seem to work at all, here are my functions.

 public static int MakeLParam(int LoWord, int HiWord)
        {
            return ((HiWord << 16) | (LoWord & 0xffff));
        }


public void leftClick(string app, int x, int y)
        {
            try
            { 
                    using (var memory = new MemorySharp(ApplicationFinder.FromProcessName(app).First()))
                {
                    memory.Windows.MainWindow.SendMessage(WindowsMessages.LButtonDown, UIntPtr.Zero, new IntPtr(MakeLParam(x, y)));
                    memory.Windows.MainWindow.SendMessage(WindowsMessages.LButtonUp, UIntPtr.Zero, new IntPtr(MakeLParam(x, y)));
                }

            }
            catch{ }
           
        }

I am trying to make it click a button of another C# application I made, but it does not work. The only way I can find to click anything is like this:

 public void leftClick(string app, int x, int y)
        {
            try
            {
                var sharp = new MemorySharp(ApplicationFinder.FromProcessName(app).First());

                // get the window
                var window = sharp.Windows.MainWindow;
                // activate it to be in foreground
                window.Activate();
                //move cursor
                window.Mouse.MoveTo(x, y);
                //left click
                window.Mouse.ClickLeft();

            }
            catch { }

        }


       button1_click(blahblah)
       {
            leftClick("APPNAMEHERE", 50(x), 50(y));
       }

Of course, that makes the windows active. Could someone help me invoke a click without making the window topmost / active at all? 

 

 

Thanks a ton, 

 

 Papa Beans


  • Back to top
  • Report




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users