Sendmessage interrupted?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Dr1ZZ
    New Member
    • Nov 2007
    • 8

    #1

    Sendmessage interrupted?

    Hi,

    I'm currently working on a bot for a game.

    It works like this:

    1: Take a picture of the current playing field
    2: Do the calculations on what i gotta do (best move)
    3: Use sendmessage to send a mouseclick to the game at the correct position

    I do this about every 2nd second.

    Most of the time its working like a charm However there is a certain instance where the game pops up a break window (its just an image in front of the playing field, showing current scores) every 5-6 minutes, its random. If my program starts a loop and does step 1, then the break window "pops up" before it's done with step 2 and 3, my mouse gets stuck.

    It moves the pointer and clicks (onto the break window which has no effect), but once the break is over, the mouse just stays stuck, while my program keeps up the process of getting the picture, calculating and sending the clicks.

    If i, once its stuck, move my mouse just a little, everything is resolved and it can keep going until it gets stuck again.

    My question is: Is there any way this is happening because of the SendMessage i use? I've tried using mouse_event instead, but its the same.

    The main handle of the window (the handle i send with the SendMessage) doesn't change when the break box pops up.

    The chances of this happening is very slim, but it's still very annoying since i cant leave my computer as it destroys my score when i gets stuck for hours.

    If anyone have any idea as to why this is happening, please help me.

    Sincerly, Drizz


    Edit: I tried switching to postmessage instead, it seems to help somewhat. I was only able to replicate the error 1/10 times vs 6-7/10 with sendmessage.. This might just be random tho. Any explanation as to why?
    Last edited by Dr1ZZ; Nov 8 '07, 09:45 PM. Reason: Added edit paragraph
  • Plater
    Recognized Expert Expert
    • Apr 2007
    • 7872

    #2
    So your trouble is that the mouse stops responding to sendmessage until you manually wiggle the physical device?

    Before you send your mouse click (but after you compute best move) can you take another screen shot and really quick decide if that popup window is in the way? Then do something accordingly?

    Comment

    • Dr1ZZ
      New Member
      • Nov 2007
      • 8

      #3
      Originally posted by Plater
      So your trouble is that the mouse stops responding to sendmessage until you manually wiggle the physical device?

      Before you send your mouse click (but after you compute best move) can you take another screen shot and really quick decide if that popup window is in the way? Then do something accordingly?
      Yep that's exactly what happens, although i don't even have to move the mouse, its enough just pressing the winkey or doing anything that sets off another message.

      It is possible to get a screenshot just before sending, but it's quite CPU consuming.. I'm actually doing this as a workaround right now :)

      It works, but I'd prefer finding the reason as to why its actually happening.

      Comment

      • Dr1ZZ
        New Member
        • Nov 2007
        • 8

        #4
        After further tests it showed that postmessage has the exact same fail ratio and requirements as sendmessage :(

        Comment

        • Plater
          Recognized Expert Expert
          • Apr 2007
          • 7872

          #5
          Could you send the message of a keypress as well? Does that "fix" the situation?

          I am thinking that in fact the window handle DOES change (perhaps to the maind handl'e child window handle?) and by sending a message to the window that isn't expected to be getting the message (since it has a child window up) it throws the message pump into dissarray?

          Comment

          • Dr1ZZ
            New Member
            • Nov 2007
            • 8

            #6
            Originally posted by Plater
            Could you send the message of a keypress as well? Does that "fix" the situation?

            I am thinking that in fact the window handle DOES change (perhaps to the maind handl'e child window handle?) and by sending a message to the window that isn't expected to be getting the message (since it has a child window up) it throws the message pump into dissarray?
            Hmn yeah it would be possible to send it as a keypress, but how would that change the situation?

            Is there any way to check for handles on childwindows? It would be an easy way to stop it from pressing, if i could check that the handle changes.

            Comment

            • Plater
              Recognized Expert Expert
              • Apr 2007
              • 7872

              #7
              It doesn't appear that MS included that ability in .NET.
              But I think the API can:

              Comment

              • Dr1ZZ
                New Member
                • Nov 2007
                • 8

                #8
                The ChildWindowFrom Point looks like its just what i need :)

                I'll try it out tomorrow, and report back how if it works :)

                Thanks a lot for your help so far.

                Comment

                • Dr1ZZ
                  New Member
                  • Nov 2007
                  • 8

                  #9
                  I tested them today, and it appears that the screen that pops up isn't a childwindow :/

                  I tried with all 3:
                  ChildWindowFrom Point
                  ChildWindowFrom PointEx (with all 4 parameters)
                  RealChildWindow FromPoint

                  All of them gave the same childwindow handle on both the normal board and the scoreboard.

                  So now I've no idea why the sendmessage doesn't get through.

                  Comment

                  Working...