GithubHelp home page GithubHelp logo

Comments (5)

GuilhermeTiede avatar GuilhermeTiede commented on June 11, 2024 1

I solved this sh!t, the problem is that you are running it on one monitor and the browser is opening on another, it ends up losing focus. It basically runs the code on the same monitor where you use the browser. This is all pyauto's fault...

from pywhatkit.

GuilhermeTiede avatar GuilhermeTiede commented on June 11, 2024

The same thing is happening to me, with Macos Sonoma. Did you find any solution?

from pywhatkit.

developeration1 avatar developeration1 commented on June 11, 2024

Just as a contribution to explain how this works, basically this is the code for almost all functions, but I will use the sendwhatmsg_instantly() as example:

def sendwhatmsg_instantly(
    phone_no: str,
    message: str,
    wait_time: int = 15,
    tab_close: bool = False,
    close_time: int = 3,
) -> None:
    """Send WhatsApp Message Instantly"""

    if not core.check_number(number=phone_no):
        raise exceptions.CountryCodeException("Country Code Missing in Phone Number!")

    web.open(f"https://web.whatsapp.com/send?phone={phone_no}&text={quote(message)}")
    time.sleep(4)
    pg.click(core.WIDTH / 2, core.HEIGHT / 2)
    time.sleep(wait_time - 4)
    pg.press("enter")
    log.log_message(_time=time.localtime(), receiver=phone_no, message=message)
    if tab_close:
        core.close_tab(wait_time=close_time)

This is on the whats.py module, the thing works as follows:

  1. Opens the window like a wa.me.
  2. waits for 4 seconds.
  3. clicks on the center of the screen.
  4. waits for the time you added to wait, less 4 seconds, to balance the time it already waited by default.
  5. Presses enter
  6. Logs stuff
  7. closes tab if you asked to.

The main issue as @GuilhermeTiede said, is pyautogui's fault, (here as pg), what this code does is mimic a user sending a message and later closing the tab, clicking on the center of the screen to "toggle" the use of the chat (thinking you will have it on Fullscreen), so if it is not precise, like having 2 screens, having a little or cornered window, or load one more second later than the 4 it uses to estimate the load time, it just does what the Whatsapp API does, but everything else goes off-rails.

An easy way to solve the majority of the issues regarding not sending the message, it's adding more wait time (in case you detect it takes more than 4 seconds to load the webapp) and preparing everything so it goes as expected, as having the browser open up in the main screen in case you have 2 or more screens.

The real solution would be throwing away pyautogui or at least the method this library is using and use a more sophisticated method to open up the window and make Python wait until the window loads and send the message wherever your window is.

P.D. First time contributing on an issue in GH, I hope I'm doing it right.

from pywhatkit.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.