大家好!今天我想向大家介绍一个非常实用的工具 ——WeChatMomentTextUnfold[1]。这个工具可以帮助你自动将粘贴的文本逐字录入到微信朋友圈,解决了朋友圈粘贴文本被折叠的问题。
为什么选择 WeChatMomentTextUnfold?
在日常使用微信时,我们常常需要分享一些长文本内容,但直接粘贴往往会导致文本被折叠,影响阅读体验。WeChatMomentTextUnfold 通过自动化的方式,帮助你轻松解决这个问题,让你的分享更加流畅。
完整代码
import pyautogui
import time
import pyperclip
import platform
import subprocess
def open_wechat_moments():
# Open WeChat (change the path to your WeChat installation if necessary)
if platform.system() == 'Darwin':
subprocess.run(["open", "-a", "WeChat"]) # For macOS
elif platform.system() == 'Windows':
subprocess.run(["start", "C:\\path\\to\\WeChat.exe"]) # Example for Windows
# os.startfile("C:\\path\\to\\WeChat.exe") # For Windows
# Wait for WeChat to open
# time.sleep(5)
# print("current position1 ",pyautogui.position())
# time.sleep(5)
# print("current position2 ",pyautogui.position())
# Move the mouse to the position of the Moments button and click
# You should replace (x, y) with the actual coordinates
time.sleep(1)
pyautogui.click(x=527, y=382) # Example coordinates for Moments button
time.sleep(1)
pyautogui.click(x=964, y=149)
time.sleep(2)
def prepare_input_field():
# Clear the clipboard and simulate a paste action to ensure focus is on the input field
pyperclip.copy("")
if platform.system() == 'Darwin':
pyautogui.hotkey('command', 'v', pressTime=0.1)
elif platform.system() == 'Windows':
pyautogui.hotkey('ctrl', 'v', pressTime=0.1)
def typewrite(char):
# Function to type a single character
pyperclip.copy(char) # Copy the character to the clipboard
if platform.system() == 'Darwin':
pyautogui.hotkey('command', 'v', pressTime=0.1) # Paste the character
elif platform.system() == 'Windows':
pyautogui.hotkey('ctrl', 'v', pressTime=0.1) # Paste the character
def type_text(text):
# Function to type the entire text character by character
for char in text:
print(char,end="")
typewrite(char)
time.sleep(0.1)
def main():
prepare_input_field()
# Define the text to be typed
text_to_type = """你要发朋友圈的文本
你要发朋友圈的文本
你要发朋友圈的文本
"""
# Wait for the user to switch to the WeChat input field
print("请将输入的焦点切换到微信朋友圈,然后不要移动鼠标")
open_wechat_moments()
# time.sleep(5)
type_text(text_to_type)
if __name__ == "__main__":
main()
使用方法
使用这个工具非常简单,只需按照以下步骤操作:
克隆代码:将代码克隆到本地。
安装 Python 环境:确保你的 Python 版本在 3.8 以上。
安装依赖库:在终端中运行以下命令安装所需的库:
pip install pyautogui
pip install pyperclip
定位微信朋友圈要点击的位置:在使用之前,你需要使用
open_wechat_moments
函数中的代码来定位微信打开朋友圈录入界面的位置:
time.sleep(5)
print("current position1 ", pyautogui.position())
等待 5 秒钟,是为了让你有充分的时间把鼠标移到正确的位置。记录下两个位置的坐标,修改代码中的坐标为你的坐标。如果你觉得这样麻烦,完全可以注释掉 open_wechat_moments
函数,加个 5 秒的延时,然后手动把输入焦点移到微信朋友圈的录入处。
替换文本:将代码中的录入文本替换为你想要分享到朋友圈的内容。
运行程序:最后,运行
main.py
文件:
python main.py
参考资料
[1]
WeChatMomentTextUnfold: https://github.com/somenzz/WeChatMomentTextUnfold。