Purebasic Interacting with other windows?

Just starting out? Need help? Post your questions and find answers here.
User avatar
matalog
Enthusiast
Enthusiast
Posts: 305
Joined: Tue Sep 05, 2017 10:07 am

Purebasic Interacting with other windows?

Post by matalog »

Is it possible for Purebasic to interact with a browser window, for example, a simple case where a PB program makes a Youtube window think someone is looking at the page every minute, so that it doesn't ask if you're still watching the videos, and cut off if you don't answer?
infratec
Always Here
Always Here
Posts: 7662
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: Purebasic Interacting with other windows?

Post by infratec »

So your title is misleading.

You want explicit check a browser and not the title of any 'other' window.
This has nothing to do with windows.

It is more a tab text or string field from an other program.

I can give you hints for your original question in Linux.
Or do you mean an other OS :wink:
If so, which one.
And which browser ?
User avatar
matalog
Enthusiast
Enthusiast
Posts: 305
Joined: Tue Sep 05, 2017 10:07 am

Re: Purebasic Interacting with other windows?

Post by matalog »

infratec wrote: Sun Feb 04, 2024 7:21 pm So your title is misleading.

You want explicit check a browser and not the title of any 'other' window.
This has nothing to do with windows.

It is more a tab text or string field from an other program.

I can give you hints for your original question in Linux.
Or do you mean an other OS :wink:
If so, which one.
And which browser ?

I want to get PB to interact with another window of a program on my PC. The title isn't misleading, that is what I want to do.

As an example of the type of thing I thought of to help describe what I aim for, I offered the broswer window interaction.

I'm using Windows and if the particular browser matters, let's say Mozilla Firefox.

I think something like

; Setting the mouse position.
SetCursorPos_(x,y)

; Simulating a left mouse click.
mouse_event_(#MOUSEEVENTF_LEFTDOWN,0,0,0,0)
mouse_event_(#MOUSEEVENTF_LEFTUP,0,0,0,0)

Would be sufficient, if I could make sure that the mouse will be under the control of PB while another window is active.
User avatar
skywalk
Addict
Addict
Posts: 4242
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: Purebasic Interacting with other windows?

Post by skywalk »

Don't mess with the mouse. :evil:
Change the idle state.
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
infratec
Always Here
Always Here
Posts: 7662
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: Purebasic Interacting with other windows?

Post by infratec »

Something like this:

Code: Select all

EnableExplicit

Define hWnd.i, Title$, Timeout.i, Rect.RECT

Timeout = 300
Repeat
  hWnd = GetForegroundWindow_()
  If hWnd
    Title$ = Space(256)
    If GetWindowText_(hWnd, @Title$, Len(Title$)) > 0
      Debug Title$
    EndIf
    
    If GetWindowRect_(hWnd, @Rect)
      Debug Str(rect\left) + "/" + Str(rect\top) + " " + Str(rect\right) + "\" + Str(rect\bottom)
    EndIf
        
    If DesktopMouseX() > rect\left And DesktopMouseX() < rect\right
      If DesktopMouseY() > rect\top And DesktopMouseY() < rect\bottom
        Debug "Inside"
        SetCursorPos_(rect\right + 1, rect\top + 1)
      Else
        Debug "Outside"
      EndIf
    Else
      Debug "Outside"
    EndIf
    
  EndIf
  Delay(100)
  Timeout - 1
Until Timeout = 0
User avatar
matalog
Enthusiast
Enthusiast
Posts: 305
Joined: Tue Sep 05, 2017 10:07 am

Re: Purebasic Interacting with other windows?

Post by matalog »

Thanks, that lets me see which other window I am interacting with.
User avatar
matalog
Enthusiast
Enthusiast
Posts: 305
Joined: Tue Sep 05, 2017 10:07 am

Re: Purebasic Interacting with other windows?

Post by matalog »

What other 'tools' does Purebasic have for interacting with other windows?

Can it 'see' pixels in them, the likes of Point(x,y), can it enter text like a keyboard entry?

Is there a set of commands I should be looking at?
infratec
Always Here
Always Here
Posts: 7662
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: Purebasic Interacting with other windows?

Post by infratec »

No.

PB can only access his own stuff with own commands.

If you want more, you have to use WIndows API stuff.
User avatar
matalog
Enthusiast
Enthusiast
Posts: 305
Joined: Tue Sep 05, 2017 10:07 am

Re: Purebasic Interacting with other windows?

Post by matalog »

Which part of the Programming reference for the Win32 API should I be looking under for those type of things?
User avatar
matalog
Enthusiast
Enthusiast
Posts: 305
Joined: Tue Sep 05, 2017 10:07 am

Re: Purebasic Interacting with other windows?

Post by matalog »

Brilliant, thanks for those.
Post Reply