how to make an online click(W,.random coord in the browser?

Just starting out? Need help? Post your questions and find answers here.
Xland
New User
New User
Posts: 7
Joined: Sun Jul 15, 2018 7:42 am

how to make an online click(W,.random coord in the browser?

Post by Xland »

how to make an online click(With random coordinates) in the browser?

for example

I run the browser

Code: Select all

Prog=RunProgram("chrome.exe","https://www.purebasic.fr/english/index.php","",#PB_Program_Open)
Delay (Random(20000,5000))
RunProgram("chrome.exe","https://www.purebasic.fr/english/index.php","",#PB_Program_Open)
Delay(Random(60000,50000))
KillProgram(Prog)
CloseProgram(Prog)
before the page is closed how to make a random click?
Xland
New User
New User
Posts: 7
Joined: Sun Jul 15, 2018 7:42 am

Re: how to make an online click(W,.random coord in the brows

Post by Xland »

I need to click the mouse only in the browser window
Evil1
User
User
Posts: 43
Joined: Fri Jul 15, 2016 8:55 pm

Re: how to make an online click(W,.random coord in the brows

Post by Evil1 »

I cobbled together the following from bits and pieces I found on the forum, it may or may not help :-

Code: Select all

RunProgram("chrome.exe","https://www.purebasic.fr/english/index.php","",#PB_Program_Open)

Global r.RECT

Procedure.l EnumWindowsProc_(lhWnd.l, lJunk.l)
  If GetWindowModuleFileName_(lhWnd, @sFileName.s{#MAX_PATH}, #MAX_PATH)
    If GetWindowText_(lhWnd, @sWindowTitle.s{#MAX_PATH}, #MAX_PATH)
      If FindString(sWindowTitle,"Chrome") 
        GetWindowRect_(lhWnd, r.RECT)
      EndIf
    EndIf
  EndIf
  ProcedureReturn #True
EndProcedure

EnumWindows_(@EnumWindowsProc_(), #Null)

SetCursorPos_(Random(r\right,r\left),Random(r\bottom,r\top))

mouse_event_(#MOUSEEVENTF_LEFTDOWN,0,0,0,0)
mouse_event_(#MOUSEEVENTF_LEFTUP,0,0,0,0)

MessageRequester("Window position","Left "+r\left+" | Right "+r\right+" | Top "+r\top+" | Bottom "+r\bottom, #PB_MessageRequester_Ok | #PB_MessageRequester_Info)
Xland
New User
New User
Posts: 7
Joined: Sun Jul 15, 2018 7:42 am

Re: how to make an online click(W,.random coord in the brows

Post by Xland »

Evil1 wrote:I cobbled together the following from bits and pieces I found on the forum, it may or may not help :-

Code: Select all

RunProgram("chrome.exe","https://www.purebasic.fr/english/index.php","",#PB_Program_Open)

Global r.RECT

Procedure.l EnumWindowsProc_(lhWnd.l, lJunk.l)
  If GetWindowModuleFileName_(lhWnd, @sFileName.s{#MAX_PATH}, #MAX_PATH)
    If GetWindowText_(lhWnd, @sWindowTitle.s{#MAX_PATH}, #MAX_PATH)
      If FindString(sWindowTitle,"Chrome") 
        GetWindowRect_(lhWnd, r.RECT)
      EndIf
    EndIf
  EndIf
  ProcedureReturn #True
EndProcedure

EnumWindows_(@EnumWindowsProc_(), #Null)

SetCursorPos_(Random(r\right,r\left),Random(r\bottom,r\top))

mouse_event_(#MOUSEEVENTF_LEFTDOWN,0,0,0,0)
mouse_event_(#MOUSEEVENTF_LEFTUP,0,0,0,0)

MessageRequester("Window position","Left "+r\left+" | Right "+r\right+" | Top "+r\top+" | Bottom "+r\bottom, #PB_MessageRequester_Ok | #PB_MessageRequester_Info)



Thank you very much almost everything works.
but some last lines,

are highlighted in red during the error

Code: Select all

SetCursorPos_(Random(r\right,r\left),Random(r\bottom,r\top))
and

Code: Select all

MessageRequester("Window position","Left "+r\left+" | Right "+r\right+" | Top "+r\top+" | Bottom "+r\bottom, #PB_MessageRequester_Ok | #PB_MessageRequester_Info)
or in another case
Perhaps I have an older version of purebasic 5.11
so the code did not work completely,
I need to take a newer version of purebasic,. ?
Xland
New User
New User
Posts: 7
Joined: Sun Jul 15, 2018 7:42 am

Re: how to make an online click(W,.random coord in the brows

Post by Xland »

I installed the version of purebasic 5.60
got better,

everything is working

but there is still a non-critical error in one line

Image


in general, the code works with a non-trivial error
and another question.
slightly improve this code

how to make two consecutive random clicks on a page?

and that the mouse cursor would also randomly move between clicks.
Xland
New User
New User
Posts: 7
Joined: Sun Jul 15, 2018 7:42 am

Re: how to make an online click(W,.random coord in the brows

Post by Xland »

and I also changed your code a bit.

why at the end of the action

the browser does not close

I added the command

Code: Select all

Delay(Random(60000,50000))
KillProgram(Prog)
CloseProgram(Prog)
below code completely


Code: Select all

RunProgram("chrome.exe","https://www.purebasic.fr/english/index.php","",#PB_Program_Open)

Global r.RECT

Procedure.l EnumWindowsProc_(lhWnd.l, lJunk.l)
  If GetWindowModuleFileName_(lhWnd, @sFileName.s{#MAX_PATH}, #MAX_PATH)
    If GetWindowText_(lhWnd, @sWindowTitle.s{#MAX_PATH}, #MAX_PATH)
      If FindString(sWindowTitle,"Chrome") 
        GetWindowRect_(lhWnd, r.RECT)
      EndIf
    EndIf
  EndIf
  ProcedureReturn #True
EndProcedure

EnumWindows_(@EnumWindowsProc_(), #Null)

Delay(Random(20000,10000))

SetCursorPos_(Random(r\right,r\left),Random(r\bottom,r\top))

mouse_event_(#MOUSEEVENTF_LEFTDOWN,0,0,0,0)
mouse_event_(#MOUSEEVENTF_LEFTUP,0,0,0,0)

MessageRequester("Window position","Left "+r\left+" | Right "+r\right+" | Top "+r\top+" | Bottom "+r\bottom, #PB_MessageRequester_Ok | #PB_MessageRequester_Info)


Delay(Random(60000,50000))
KillProgram(Prog)
CloseProgram(Prog)

and yet, the click does not happen with random coordinates.

clicks always in the top header of the web page
Xland
New User
New User
Posts: 7
Joined: Sun Jul 15, 2018 7:42 am

Re: how to make an online click(W,.random coord in the brows

Post by Xland »

Now a little bit has changed the code with the coordinates

Code: Select all

RunProgram("chrome.exe","https://www.purebasic.fr/english/index.php","",#PB_Program_Open)

Global r.RECT

Procedure.l EnumWindowsProc_(lhWnd.l, lJunk.l)
  If GetWindowModuleFileName_(lhWnd, @sFileName.s{#MAX_PATH}, #MAX_PATH)
    If GetWindowText_(lhWnd, @sWindowTitle.s{#MAX_PATH}, #MAX_PATH)
      If FindString(sWindowTitle,"Chrome") 
        GetWindowRect_(lhWnd, r.RECT)
      EndIf
    EndIf
  EndIf
  ProcedureReturn #True
EndProcedure

EnumWindows_(@EnumWindowsProc_(), #Null)

Delay (Random(5000,2000))

SetCursorPos_(Random(r\right,r\left),Random(r\bottom,r\top))

Temp.POINT ;
MouseX=(Random(8, 900));
MouseY=(Random(8, 800))

MessageRequester("Window position","Left "+r\left+" | Right "+r\right+" | Top "+r\top+" | Bottom "+r\bottom, #PB_MessageRequester_Ok | #PB_MessageRequester_Info)


Delay (Random(6000,5000))
KillProgram(Prog)
CloseProgram(Prog)




and here I also made a mistake, clicking does not happen in the browser window.

clicks elsewhere

and the browser after the action, does not close

Code: Select all

KillProgram(Prog)
CloseProgram(Prog)
experimenting, I'm not entirely sure,
but it seems click occurs
  not in the browser window.
click occurs in the computer operating system window

Code: Select all

RunProgram("chrome.exe","https://www.purebasic.fr/english/index.php","",#PB_Program_Open)

Global r.RECT

Procedure.l EnumWindowsProc_(lhWnd.l, lJunk.l)
  If GetWindowModuleFileName_(lhWnd, @sFileName.s{#MAX_PATH}, #MAX_PATH)
    If GetWindowText_(lhWnd, @sWindowTitle.s{#MAX_PATH}, #MAX_PATH)
      If FindString(sWindowTitle,"Chrome") 
        GetWindowRect_(lhWnd, r.RECT)
      EndIf
    EndIf
  EndIf
  ProcedureReturn #True
EndProcedure

EnumWindows_(@EnumWindowsProc_(), #Null)


Delay(Random(20000,10000))


Temp.POINT ;
MouseX=(Random(800, 9)) ;
MouseY=(Random(800, 9))
GetCursorPos_(@Temp) ;
SetCursorPos_(MouseX, MouseY) ;
mouse_event_(#MOUSEEVENTF_ABSOLUTE | #MOUSEEVENTF_LEFTDOWN, MouseX,MouseY,0,0) ; 
Delay(Random(60000, 3600)) ;
mouse_event_(#MOUSEEVENTF_ABSOLUTE | #MOUSEEVENTF_LEFTUP, MouseX,MouseY,0,0) ; 
SetCursorPos_(Temp\x, Temp\y) ;
mouse_event_(#MOUSEEVENTF_LEFTDOWN,0,0,0,0)
mouse_event_(#MOUSEEVENTF_LEFTUP,0,0,0,0)

MessageRequester("Window position","Left "+r\left+" | Right "+r\right+" | Top "+r\top+" | Bottom "+r\bottom, #PB_MessageRequester_Ok | #PB_MessageRequester_Info)

Delay (Random(6000,5000))
KillProgram(Prog)
CloseProgram(Prog)

but here different values
so the program did not automatically close

Code: Select all

RunProgram("chrome.exe","https://www.purebasic.fr/english/index.php","",#PB_Program_Open)
instead

Code: Select all

Prog=RunProgram("chrome.exe","https://www.purebasic.fr/english/index.php","",#PB_Program_Open)

Code: Select all

Delay (Random(6000,5000))
KillProgram(Prog)
CloseProgram(Prog)
Post Reply