sending mouseclick to other coordinate without movin[SOLVED]

Just starting out? Need help? Post your questions and find answers here.
.:M:.
New User
New User
Posts: 7
Joined: Sun Jul 20, 2008 7:34 am

sending mouseclick to other coordinate without movin[SOLVED]

Post by .:M:. »

hello,
is it possible?

i have found no way to "simulate" a Lbutton mouseclick without moving the cursor to exact that point to be clicked.

sendmessage() and mouse_event() have no effect without setting the cursor
before.

why isn't it possible?
Or is there still another way?

thanx a lot.
Last edited by .:M:. on Tue Jul 22, 2008 7:28 am, edited 1 time in total.
Derek
Addict
Addict
Posts: 2354
Joined: Wed Apr 07, 2004 12:51 am
Location: England

Post by Derek »

Welcome to the forums, try this.

Code: Select all

OpenWindow(0,0,0,800,600,"",$ca0001)
CreateGadgetList(WindowID(0))
ButtonGadget(1,100,100,100,30,"pressed")
Repeat
   If GetAsyncKeyState_(#VK_LBUTTON) And GetActiveWindow()=0
      SendMessage_(GadgetID(1),#WM_LBUTTONDOWN,0,0)
   EndIf
Until WaitWindowEvent()=16
User avatar
Rook Zimbabwe
Addict
Addict
Posts: 4322
Joined: Tue Jan 02, 2007 8:16 pm
Location: Cypress TX
Contact:

Post by Rook Zimbabwe »

This would be perfect to force someone to click OK to download malware! :twisted:
Binarily speaking... it takes 10 to Tango!!!

Image
http://www.bluemesapc.com/
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Post by PB »

But it doesn't do what M wanted, which is to click the mouse at a specific point
without moving the mouse there. I don't think that's possible.
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

Well, sending a #WM_LBUTTONDOWN to a window/control with lParam holding the relevant client coordinates works okay for general GUI stuff. I've done this before without a problem. It does depend on what the aim of this is though - I mean you will not be able to synthesise a button click, for example, by doing this.

For screens and/or general desktop... well, that's another matter! :)
I may look like a mule, but I'm not a complete ass.
Derek
Addict
Addict
Posts: 2354
Joined: Wed Apr 07, 2004 12:51 am
Location: England

Post by Derek »

Rook Zimbabwe wrote:This would be perfect to force someone to click OK to download malware! :twisted:
Only if you can get the id or whatever of the button you want to click.

Anyway I was assuming he wanted to click on a gadget in a PB program without moving the mouse. Maybe if we are told more of what is needed then it can be figured out. :?
.:M:.
New User
New User
Posts: 7
Joined: Sun Jul 20, 2008 7:34 am

Post by .:M:. »

Hello,

It's for interacting with a WebGadget!

Ok, i want to klick the Button and then automaticly a leftclick should be done on a link in the webgadget.

i have made so many tests and code examples, but nothing works, i think its something wrong with the handle, or the coordinates?

This is my test, but nothing happens?

Code: Select all

Enumeration 
  #Web1
  #Button1 
EndEnumeration 

Procedure WindowOpen() 
  OpenWindow(1,0,0,500,400,"Window",#PB_Window_TitleBar|#PB_Window_MinimizeGadget|#PB_Window_ScreenCentered) 
  CreateGadgetList(WindowID(1))  
    ButtonGadget(#Button1, 10, 10, 40, 20, "Test")
    WebGadget(#Web1, 10, 40, 480, 320, "www.google.de")
EndProcedure 

Procedure MakelParam(low.w, high.w)
  ProcedureReturn low + (high << 16)
EndProcedure

Procedure SimulateClick()
  mx.w= 473 ; These Coordinates are where a link should be, please check
  my.w= 376
  lParam = MakelParam(mx.w, my.w)
  SendMessage_(WindowID(1),#WM_LBUTTONDOWN,0,lParam) 
  SendMessage_(WindowID(1),#WM_LBUTTONUP,0,lParam) 
EndProcedure

Procedure EventHandling()
  Repeat 
    ;GetCursorPos_(pt.POINT)    ; Check Please where a Link is set in your WebGadget, I have used google germany.
 	  ;Debug "x:" + Str(pt\x) + "y:" + Str(pt\y)
    EventID=WaitWindowEvent() 
    Select EventID 
      Case #PB_Event_Gadget 
        Select EventGadget() 
          Case #Button1 	
              SimulateClick()     
        EndSelect 
    EndSelect
  Until EventID=#PB_Event_CloseWindow
  CloseWindow(1) 
  End
EndProcedure

Procedure Main()
  WindowOpen()
  EventHandling()
EndProcedure

Main()
.:M:.
New User
New User
Posts: 7
Joined: Sun Jul 20, 2008 7:34 am

Post by .:M:. »

Ok, I got it.

The problem with the webgadget is, that the gadgetid() isn't the handle of the browser inside the gadget :idea:

I have tested with WindowFromPoint().
With the real handle u can simulate clicks into "the browser inside the webgadget :-)", on every x/y coordinate u want to.

Now i'm looking for another way to get the handle, because the user shouldn't move over the webgadget.
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post by Sparkie »

.:M:. wrote:...because the user shouldn't move over the webgadget
Why not let the user do their own mouse clicking? What are you trying to accomplish here?
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
Derek
Addict
Addict
Posts: 2354
Joined: Wed Apr 07, 2004 12:51 am
Location: England

Post by Derek »

He could be trying to insert data into googles search instead of the user having to type it but you are right it does seem a bit strange.
User avatar
Rook Zimbabwe
Addict
Addict
Posts: 4322
Joined: Tue Jan 02, 2007 8:16 pm
Location: Cypress TX
Contact:

Post by Rook Zimbabwe »

See!

Age and Paranoia will always triumph over youth and stupidity!

You all know those fake popups on the porn sites and fake AV sites (that I never go to!) that say CLICK OK or CANCEL... My bet is he wants to trap the closewindow X and make it OK
Binarily speaking... it takes 10 to Tango!!!

Image
http://www.bluemesapc.com/
.:M:.
New User
New User
Posts: 7
Joined: Sun Jul 20, 2008 7:34 am

Post by .:M:. »

You all know those fake popups on the porn sites and fake AV sites (that I never go to!) that say CLICK OK or CANCEL... My bet is he wants to trap the closewindow X and make it OK

no, thats to easy!
my program will let the user have a long and hard fight with his mouse...

http://www.youtube.com/watch?v=PE_YZf6-gRY

:-)

Sure, I need these functions for automatisation (thats the reason computers were built for), but not the kind you think of.
i need it for parallelisation (multithreadding) of webgadgets for faster access and better usuability of special websites.
it's neccessary for faster searching, filtering the hits, display the content etc... all confirm to user-agreements.

theres a good reason why not to use special-website-apis, everyone
who has programmed similar applications knows why - api-calls almost have traffic limit and then u have to pay for more.
i will never agree to that - not if i program free applications for everyone.
Post Reply