Page 1 of 1

Purebasic Interacting with other windows?

Posted: Sun Feb 04, 2024 5:56 pm
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?

Re: Purebasic Interacting with other windows?

Posted: Sun Feb 04, 2024 7:21 pm
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 ?

Re: Purebasic Interacting with other windows?

Posted: Sun Feb 04, 2024 7:43 pm
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.

Re: Purebasic Interacting with other windows?

Posted: Sun Feb 04, 2024 8:52 pm
by skywalk
Don't mess with the mouse. :evil:
Change the idle state.

Re: Purebasic Interacting with other windows?

Posted: Sun Feb 04, 2024 9:51 pm
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

Re: Purebasic Interacting with other windows?

Posted: Sun Feb 04, 2024 10:50 pm
by matalog
Thanks, that lets me see which other window I am interacting with.

Re: Purebasic Interacting with other windows?

Posted: Tue Feb 06, 2024 5:34 pm
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?

Re: Purebasic Interacting with other windows?

Posted: Tue Feb 06, 2024 5:55 pm
by infratec
No.

PB can only access his own stuff with own commands.

If you want more, you have to use WIndows API stuff.

Re: Purebasic Interacting with other windows?

Posted: Tue Feb 06, 2024 6:26 pm
by matalog
Which part of the Programming reference for the Win32 API should I be looking under for those type of things?

Re: Purebasic Interacting with other windows?

Posted: Tue Feb 06, 2024 7:53 pm
by infratec

Re: Purebasic Interacting with other windows?

Posted: Thu Feb 08, 2024 1:49 am
by matalog
Brilliant, thanks for those.