Ankit404butfound / PyWhatKit

Send WhatsApp message at certain time and many other things.
MIT License
1.34k stars 295 forks source link

Not able to send message using sendwhatmsg function #173

Closed theCJMan closed 2 years ago

theCJMan commented 2 years ago

This issue is Based on #20 However #20 was closed yet I see several people still have an issue and This is still an issue for me.

My Environment

Chrome Version 97.0.4692.71 (Official Build) (64-bit) Win 10 V 21H1 2 monitors (Laptop screen plus 1 HDMI) Line speed 20m/s

PyWhatKit 5.3 Python 3.9

The Code

I had to include flask else the code would not work,

import pywhatkit as wu
import flask

wu.sendwhatmsg_instantly("+27790995412", "Test this now", 15)

What I found:

When code (PyCharm) is on main screen and browser on the other:

  1. PyCharm has focus (naturally)
  2. New tab opens and load WhatsApp (Chrome has focus now)
  3. Message is typed in text area BUT not sent
  4. Seems + is pressed (sent) and then an enter is sent (This leaves an additional new line in the code)
  5. Code ends

When code (PyCharm) AND browser on the other screen :

  1. PyCharm has focus (naturally)
  2. New tab opens and load WhatsApp (Chrome has focus now)
  3. Message is typed in text area BUT not sent
  4. Seems + is pressed (sent) and then an enter is sent 3.1. NOTE the "3rd" window or app was my FileExplorer and a word doc was highlighted 3.2. The result of the alt tab is that the File explorer receives focus and when the enter is pressed then the highlighted file (word doc) is opened...
  5. Code ends

When code (PyCharm) AND browser on the MAIN screen :

  1. PyCharm has focus (naturally)
  2. New tab opens and load WhatsApp (Chrome has focus now)
  3. Message is typed in text area BUT not sent
  4. NOTE now it seems NOT to do an + 3.1. It seems the focus is still in the browser and in the WhatsApp tab...
  5. Code ends

My Fix

I am keeping the Code and Chrome on the main screen. and had to add a few lines of code to "send" the message

import pywhatkit as wu
import flask
import pyautogui as pg

wu.sendwhatmsg_instantly("+27790995412", "Test this now", 15)
for i in range(10):
    pg.press("tab")
pg.press("enter")
theCJMan commented 2 years ago

Duplicate of #149