Results 1 to 11 of 11

Thread: Virtual Mouse Click/Movement Method help Delphi

  1. #1
    Join Date
    May 2007
    Location
    England/Liverpool
    Posts
    1,004
    Mentioned
    9 Post(s)
    Quoted
    106 Post(s)

    Default Virtual Mouse Click/Movement Method help Delphi

    Hello villavu long time since actively posting but life has been busy and good now 30 years old with a 10 year old daughter asking me to create a bot for them with the little time i get on my desktop im starting to struggle to get what i had envisioned.

    Simba Code:
    procedure CrAPPA.GhostMouse(X, Y, ClickType: Integer);
    var
      Pos: TPoint;
    begin
      Pos := Target.ScreenToClient(point(X, Y));
      case ClickType of
        0:
          begin
          //Target.Perform(WM_SETFOCUS, Target, null);
    //test  Sendmessage(Target, WM_MOUSEMOVE, 0, MakeLParam(Pos.X, Pos.Y));
            sendmessage(Target, WM_LBUTTONDOWN, MK_LBUTTON, MakeLParam(Pos.X, Pos.Y));
            Wait(100);
            sendmessage(Target, WM_LBUTTONUP, MK_LBUTTON, MakeLParam(Pos.X, Pos.Y));
          end;
        1:
          begin
            PostMessageA(Target, WM_RBUTTONDOWN, MK_RBUTTON, MakeLParam(Pos.X, Pos.Y));
            Wait(100);
            PostMessageA(Target, WM_RBUTTONUP, MK_RBUTTON, MakeLParam(Pos.X, Pos.Y));
          end;
      end;
    end;

    She wants the bot to run without losing control of her computer first thing that sprung to mind was the old GhostMouse for scar by kaitnieks
    and this is the best i can come up with to my knowledge to replicate it.
    I've also had trouble with PostMessage when left clicking while SendMessage seems to Correct this issue by forcing the message ahead of all i'm still facing problems while form has focus it misses the odd click yet the real mouse does not enter the forms bounds yet while selecting any other window to remove focus it works flawless.

    I'm now asking for help with what method should i be using to accomplish this i have tried to find articles on how to create a secondary cursor like teamviewer but within my app blocked from all interference but cant find any infomation other than software which allows two hardware mice.
    Previously Known or not Known as CRU1Z1N.
    If you want to succeed you should strike out on new paths, rather than travel the worn paths of accepted success.(John D. Rockefeller)

  2. #2
    Join Date
    Feb 2011
    Location
    The Future.
    Posts
    5,600
    Mentioned
    396 Post(s)
    Quoted
    1598 Post(s)

    Default

    Quote Originally Posted by Mark View Post
    ...

    Note you can only use SendMessage and PostMessage for mice events and not keyboard events.. What do you mean it misses events? PostMessage is asynchronous so it returns immediately. SendMessage is synchronous and waits until the receiving window actually processes the event. I can't see them failing unless the receiving window has lost focus. That is the only time they usually fail. Perhaps try requesting focus on the child window and then sending the event.

    Also, you should use SendInput.. You can create your own cursor with: CreateCursor but you'd still have to process all events yourself.
    Last edited by Brandon; 11-05-2017 at 01:04 AM.
    I am Ggzz..
    Hackintosher

  3. #3
    Join Date
    May 2007
    Location
    England/Liverpool
    Posts
    1,004
    Mentioned
    9 Post(s)
    Quoted
    106 Post(s)

    Default

    Quote Originally Posted by Brandon View Post
    .
    Thankyou pal looking exactly like what ive missed will start experimenting with creating my cursor then control +rep(if i could)

    Edit: im not sure what the problem is ive tried to force focus to the TwebBrowser component tho that does defeat the object im trying to achieve here with giving her full control over her computer still.
    im going to try using SendInput and creating a visual cursor withing the application i will post my result thanks again.
    Last edited by Mark; 11-05-2017 at 01:27 AM.
    Previously Known or not Known as CRU1Z1N.
    If you want to succeed you should strike out on new paths, rather than travel the worn paths of accepted success.(John D. Rockefeller)

  4. #4
    Join Date
    May 2012
    Location
    Glorious Nippon
    Posts
    1,011
    Mentioned
    50 Post(s)
    Quoted
    505 Post(s)

    Default

    Quote Originally Posted by Mark View Post
    (op)
    I use something like this:
    Simba Code:
    procedure MOUSE(const HWND: HWND; P: TPoint; BUTTON: Byte; DownTime: Int32 = 75);
    var
      LPA: LPARAM;
    begin
      if ( (BUTTON < 0) or (BUTTON > 3) ) then exit;

      LPA := MAKELPARAM(P.X, P.Y);

      case BUTTON of
        0:
        begin
          PostMessage(HWND, WM_RBUTTONDOWN, MK_RBUTTON, LPA);
          sleep(DownTime);
          PostMessage(HWND, WM_RBUTTONUP, 0, LPA);
          sleep(4);
        end;
        1:
        begin
          PostMessage(HWND, WM_LBUTTONDOWN, MK_LBUTTON, LPA);
          sleep(DownTime);
          PostMessage(HWND, WM_LBUTTONUP, 0, LPA);
          sleep(4);
        end;
      end;

      PostMessage(HWND, WM_MOUSEMOVE, 0, LPA);
    end;
    it might freak out if you try to use your real mouse on the game, so I'd pause the script if you want to do anything manually.

    Quote Originally Posted by Brandon View Post
    Note you can only use SendMessage and PostMessage for mice events and not keyboard events..
    Why not? I've been doing it for months, botting mobile games on Nox.

  5. #5
    Join Date
    Feb 2011
    Location
    The Future.
    Posts
    5,600
    Mentioned
    396 Post(s)
    Quoted
    1598 Post(s)

    Default

    Quote Originally Posted by Citrus View Post
    Why not? I've been doing it for months, botting mobile games on Nox.
    You've been using un-reliable WinAPI programming for months then.. I'm not sure what Nox is. I'm glad it worked for you though. If it still works, then why stop I guess..

    But anyway..

    Not all applications process input events through WPARAM or LPARAM.. especially because most apps use GetAsyncKeyState or GetKeyState to determine if a key was pressed (Games do this in their GameLoop.. others use RawInput or DirectInput). If that's the case, SendMessage and PostMessage will never work and will instead pass straight through the event queue with no results.

    See here: https://blogs.msdn.microsoft.com/old...30-11/?p=35513
    Last edited by Brandon; 11-05-2017 at 05:27 AM.
    I am Ggzz..
    Hackintosher

  6. #6
    Join Date
    May 2012
    Location
    Glorious Nippon
    Posts
    1,011
    Mentioned
    50 Post(s)
    Quoted
    505 Post(s)

    Default

    Quote Originally Posted by Brandon View Post
    You've been using un-reliable WinAPI programming for months then.. I'm not sure what Nox is. I'm glad it worked for you though. If it still works, then why stop I guess..

    But anyway..

    Not all applications process input events through WPARAM or LPARAM.. especially because most apps use GetAsyncKeyState or GetKeyState to determine if a key was pressed (Games do this in their GameLoop.. others use RawInput or DirectInput). If that's the case, SendMessage and PostMessage will never work and will instead pass straight through the event queue with no results.

    See here: https://blogs.msdn.microsoft.com/old...30-11/?p=35513
    That's fair. I wouldn't expect my hacky plugins to work everywhere, but they do work for me. SendInput wouldn't work AFAIK, because I'm botting 2+ things simultaneously and don't want to mess with focus or whatever.
    btw Nox is an Android emulator.

  7. #7
    Join Date
    Dec 2006
    Location
    Banville
    Posts
    3,914
    Mentioned
    12 Post(s)
    Quoted
    98 Post(s)

    Default

    Quote Originally Posted by Brandon View Post
    Note you can only use SendMessage and PostMessage for mice events and not keyboard events.
    Why? The documentation does not mention this at all.
    The jealous temper of mankind, ever more disposed to censure than
    to praise the work of others, has constantly made the pursuit of new
    methods and systems no less perilous than the search after unknown
    lands and seas.

  8. #8
    Join Date
    May 2012
    Location
    Glorious Nippon
    Posts
    1,011
    Mentioned
    50 Post(s)
    Quoted
    505 Post(s)

    Default

    Quote Originally Posted by R0b0t1 View Post
    Why? The documentation does not mention this at all.
    Quote Originally Posted by Brandon View Post
    Not all applications process input events through WPARAM or LPARAM.. especially because most apps use GetAsyncKeyState or GetKeyState to determine if a key was pressed (Games do this in their GameLoop.. others use RawInput or DirectInput). If that's the case, SendMessage and PostMessage will never work and will instead pass straight through the event queue with no results.

    See here: https://blogs.msdn.microsoft.com/old...30-11/?p=35513
    Scroll up lmao

  9. #9
    Join Date
    Oct 2011
    Posts
    805
    Mentioned
    21 Post(s)
    Quoted
    152 Post(s)

  10. #10
    Join Date
    Dec 2006
    Location
    Banville
    Posts
    3,914
    Mentioned
    12 Post(s)
    Quoted
    98 Post(s)

    Default

    Quote Originally Posted by Citrus View Post
    Scroll up lmao
    I did miss that, but the blog post is fairly disingenuous. Whether it will work just needs to be tested on a case-by-case basis. I don't think it makes sense to tell people to never create event messages to simulate input. I am dismayed that this means it is not possible to simulate input to a program in every case.

    Per Microsoft's own documentation, they recommend the message queue for all mouse and keyboard input.
    The jealous temper of mankind, ever more disposed to censure than
    to praise the work of others, has constantly made the pursuit of new
    methods and systems no less perilous than the search after unknown
    lands and seas.

  11. #11
    Join Date
    Oct 2011
    Posts
    805
    Mentioned
    21 Post(s)
    Quoted
    152 Post(s)

    Default

    I've met two kinds of applications: those which can handle WM_MESSAGEs input (browsers, many windows applications, flash games) and those who can not (most of regular games). I don't see where is a problem - you choose virtualisation method you need.
    The biggest benefit of PostMessage is - it doesn't interfere with your hardware mouse, you can bot in the background, even in minimised state (although you need it not-minimised if you use Simba to grab image).
    I don't see how could you do with DirectInput or SendInput without using VM.

    Quote Originally Posted by Brandon
    I understand what blog article says - when I use WM_KEYUP it checks for the real state of shift - so the output (capital letter or not) depends on if you actually pressed shift or not. But it's not a big deal, it doesn't mean that you can't send text with capital letters to application - you can do it using WM_CHAR.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •