Send mouseclick without activating window?

Just starting out? Need help? Post your questions and find answers here.
Mistrel
Addict
Addict
Posts: 3415
Joined: Sat Jun 30, 2007 8:04 pm

Send mouseclick without activating window?

Post by Mistrel »

Is it possible to send a mouseclick to a window without activating it?
Marco2007
Enthusiast
Enthusiast
Posts: 648
Joined: Tue Jun 12, 2007 10:30 am
Location: not there...

Post by Marco2007 »

Maybe if the window is disabled with DisableWindow().
But I don`t know, what you want to do...
PureBasic for Windows
Mistrel
Addict
Addict
Posts: 3415
Joined: Sat Jun 30, 2007 8:04 pm

Post by Mistrel »

It can probably be done with a SendMessage but it's not working to the control's hwnd. I remember there being some special message that needed to be used for the message to reach the control. Does anyone know what this is?
User avatar
eddy
Addict
Addict
Posts: 1479
Joined: Mon May 26, 2003 3:07 pm
Location: Nantes

Post by eddy »

Did you try PostMessage_() ?
Imagewin10 x64 5.72 | IDE | PB plugin | Tools | Sprite | JSON | visual tool
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post by Sparkie »

I've had success using PostMessage_() and or SendMessage() with any one of the following:

#WM_LBUTTONDOWN
#WM_LBUTTONUP

#WM_COMMAND/#BN_CLICK

#BM_CLICK

As for the not activating part of it... well so far I can only manage to get that to work after the initial click. :?

***Edit*** Now that I take a closer look, ignore my last sentence. The window does not activate when I send the button click.
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
User avatar
Rook Zimbabwe
Addict
Addict
Posts: 4322
Joined: Tue Jan 02, 2007 8:16 pm
Location: Cypress TX
Contact:

Post by Rook Zimbabwe »

But the mouseclick can still activate a process in your main program... provided you created both windows from the same program.
Binarily speaking... it takes 10 to Tango!!!

Image
http://www.bluemesapc.com/
Mistrel
Addict
Addict
Posts: 3415
Joined: Sat Jun 30, 2007 8:04 pm

Post by Mistrel »

The button turns out to be part of a custom button-image or something. That's why it wasn't working. I still can't get it to click but it's not important anymore. I found a much simpler solution to my problem. Thank you for you help. :)
gildev
User
User
Posts: 10
Joined: Sat Aug 23, 2008 12:58 am
Location: Picardie (France)

Post by gildev »

I found a much simpler solution to my problem
What is your solution please?
Mistrel
Addict
Addict
Posts: 3415
Joined: Sat Jun 30, 2007 8:04 pm

Post by Mistrel »

The program runs in a loop expecting a certain message to intercept instead of activating it.
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post by Sparkie »

Mistrel wrote:I still can't get it to click but it's not important anymore.
Where's your sense of adventure...your curiosity...how can you ignore that challenge...you gonna let that whimpy little button get the best of you :?:

Send it over here and I'll show it what these 8 fingers and 2 opposable thumbs can do :twisted:

jk... :wink:

Glad to see you found a workaround for this Mistrel. :)
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
Mistrel
Addict
Addict
Posts: 3415
Joined: Sat Jun 30, 2007 8:04 pm

Post by Mistrel »

Ok, Sparkie I'll give it to you. ;)

Download AC Tool and use this script:

Code: Select all

bell
Your objective is to figure out how to send a mouseclick to the "Start" button control. And no cheating by hard-coding an off-set from the bottom-right corner of the screen.

I couldn't figure out how to send a message to this control to simulate a mouse button. The "Start" button doesn't appear to be a real button. You can confirm this with a tool like Winspector.

The correct way to do it is to have the script loop as quickly as you want and check for keyboard events that way. So, start the script once and loop it instead of each time you want it to do something.

Don't fail me in this mission, snake!
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post by Sparkie »

Code: Select all

Macro MakeLong(low, high) 
low | high <<16 
EndMacro 

hParent = FindWindow_("TfrmMain", 0)
If hParent
  hChild1 = FindWindowEx_(hParent, 0, "TPageControl", 0)
  If hChild1
    hChild2 = FindWindowEx_(hChild1, 0, "TTabSheet", "Commands and Macros")
    If hChild2
      hChild3 = FindWindowEx_(hChild2, 0, "TPanel", 0)
      If hChild3
        hChild4 = FindWindowEx_(hChild3, 0, "TPanel", 0)
        If hChild4
          hChild5 = FindWindowEx_(hChild4, 0, "TPanel", 0)
          If hChild5
            pause = 1000
            For bell = 1 To 5
              SendMessage_(hChild5, #WM_LBUTTONDOWN, 0, MakeLong(10, 60))
              Delay(100)
              SendMessage_(hChild5, #WM_LBUTTONUP, 0, MakeLong(10, 60))
              Delay(pause)
            Next
          EndIf
        EndIf
      EndIf
    EndIf
  EndIf
EndIf
Last edited by Sparkie on Wed Aug 27, 2008 9:51 pm, edited 1 time in total.
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
Mistrel
Addict
Addict
Posts: 3415
Joined: Sat Jun 30, 2007 8:04 pm

Post by Mistrel »

I'm always impressed, Sparkie. You make it look so easy. :)

Thank you for this great example of navigating child controls with FindWindowEx. I hadn't thought of ever using it in such a dynamic way.
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post by Sparkie »

Thanks for the challenge Mistrel 8)
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post by Sparkie »

By the way, I noticed a slight bug with my Delay() so I edited the code to fix it.
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
Post Reply