Python實現微信表情包炸群功能

Python實現微信表情包炸群效果,具體代碼如下所示;

# -*- coding = utf-8 -*-
# @Time : 2021/1/26 15:19
# @Author : 陳良興
# @File : 微信表情包炸群.py
# @Software : PyCharm

# 運行程序 > 輸入次數 > 回車 > 打開微信對話框 > 將鼠標放置在“發送”按鈕處即可

from pynput.keyboard import Controller as KB        #控制鍵盤輸入
from pynput.mouse import Controller,Button         #控制鼠標點擊
import time
import random

Wechat_expression = [
  "[微笑]","[撇嘴]","[色]","[發呆]","[得意]","[流淚]","[害羞]","[閉嘴]","[睡]","[大哭]","[尷尬]",
  "[發怒]","[調皮]","[呲牙]","[驚訝]","[難過]","[囧]","[抓狂]","[吐]","[偷笑]","[愉快]","[白眼]",
  "[傲慢]","[困]","[驚恐]","[憨笑]","[悠閑]","[咒罵]","[疑問]","[噓]","[暈]","[衰]","[骷髏]","[豬頭]",
  "[敲打]","[再見]","[擦汗]","[摳鼻]","[鼓掌]","[壞笑]","[右哼哼]","[鄙視]","[委屈]","[快哭瞭]",
  "[陰險]","[親親]","[可憐]","[笑臉]","[生病]","[臉紅]","[破涕為笑]","[恐懼]","[失望]","[無語]",
  "[嘿哈]","[捂臉]","[奸笑]","[機智]","[皺眉]","[耶]","[吃瓜]","[加油]","[汗]","[天啊]","[Emm]",
  "[社會社會]","[旺柴]","[好的]","[打臉]","[哇]","[翻白眼]","[666]","[讓我看看]","[嘆氣]","[苦澀]",
  "[裂開]","[嘴唇]","[愛心]","[心碎]","[擁抱]","[強]","[弱]","[握手]","[勝利]","[抱拳]","[勾引]",
  "[拳頭]","[OK]","[合十]","[啤酒]","[咖啡]","[蛋糕]","[玫瑰]","[凋謝]","[菜刀]","[便便]","[月亮]",
  "[太陽]","[禮物]","[紅包]","[發]","[福]","[跳跳]","[發抖]","[轉圈]","[炸彈]","[慶祝]","[煙花]"
]

#鍵盤控制函數
def keyboardInput(string):
  keyboard = KB()
  keyboard.type(string)

#鼠標控制函數
def mouseClick():
  mouse = Controller()
  mouse.press(Button.left)
  mouse.release(Button.left)

#響應函數
def response(number):
  time.sleep(5)             #延遲5s響應
  for i in range(number):
    sentence = random.choice(Wechat_expression)
    keyboardInput(sentence)
    mouseClick()
    time.sleep(0.4)           #每條消息間隔0.4秒


if __name__ == "__main__":
  while True:
  	print("\033[1;32m發動機已啟動,隨時可以出發!\033[0m")
    Num = input("\033[1;32m請輸入轟炸次數:\033[0m")
    if Num.isdigit():
      response(int(Num))
      print("\033[1;33m報告長官,轟炸完畢,請求下一步作戰計劃!!!\033[0m")
    else:
      print("\033[1;31m輸入錯誤,請重新輸入一個整數!!!\033[0m")

    #詢問是否繼續
    answer = input("\033[1;34m是否執行下一次作戰計劃?(y 或者 n):\033[0m")
    if answer == "y":
      print("\033[1;33m繼續轟炸!!!\033[0m")
      continue
    if answer == "n":
      print("\033[1;33m停止轟炸,給他們喘口氣!!!\033[0m")
      break
    else:
      print("\033[1;31m輸入錯誤,請輸入“y”或者“n”!!!\033[0m")

操作如下:

首先,運行代碼,輸入次數。

在這裡插入圖片描述

然後,打開微信對話框,將鼠標放置在“發送”按鈕處,即可實現自動隨機發送表情包。

在這裡插入圖片描述

最後,根據自己的選擇是否繼續執行操作。

在這裡插入圖片描述

到此這篇關於Python實現微信表情包炸群功能的文章就介紹到這瞭,更多相關Python微信表情包炸群內容請搜索WalkonNet以前的文章或繼續瀏覽下面的相關文章希望大傢以後多多支持WalkonNet!

推薦閱讀: