找回密码
 加入
搜索
查看: 2446|回复: 6

[AU3基础] weixin窗口写入发送示例【已解决】

[复制链接]
发表于 2020-8-3 11:25:02 | 显示全部楼层 |阅读模式
本帖最后由 rhci 于 2020-8-3 15:35 编辑

目的:按ini文件指定时间发送指定人,指定语句。
已实现:按时间,指定人,指定语句。
未时间:后台沉睡,判断时间,激活程序,发送
#include <Misc.au3>
#include <Process.au3>
$g_szVersion = "自我检测1"
If WinExists($g_szVersion) Then Exit
AutoItWinSetTitle($g_szVersion)
HotKeySet("!^{x}", "ext");退出快捷键为ALT+Ctrl+x键
AdlibRegister("_ReduceMemory", 60000);每60秒执行一次内存释放
MsgBox(0,"", '程序已开始运行退出快捷键为ALT+Ctrl+x键.',3)
While 1
        If FileExists(@ScriptDir & "\timec.ini") Then
        Local $time1 = IniRead("timec.ini","参数","时间1","time1")
        Local $time2 = IniRead("timec.ini","参数","时间2","time2")
        Local $time3 = IniRead("timec.ini","参数","时间3","time3")
        Local $unmes = IniRead("timec.ini","参数","对象名","$unmes")
        Local $str1 = IniRead("timec.ini","参数","早安","str1")
        Local $str2 = IniRead("timec.ini","参数","午安","str2")
        Local $str3 = IniRead("timec.ini","参数","晚安","str3")
        Else
                IniWrite(@ScriptDir & "\timec.ini", "参数", "时间1", "发送时间请用纯数字表示比如1630表示16点30分")
                IniWrite(@ScriptDir & "\timec.ini", "参数", "时间2", "发送时间请用纯数字表示比如1630表示16点30分")
                IniWrite(@ScriptDir & "\timec.ini", "参数", "时间3", "发送时间请用纯数字表示比如1630表示16点30分")
                IniWrite(@ScriptDir & "\timec.ini", "参数", "对象名", "需要发给谁,不要有特殊符号")
                IniWrite(@ScriptDir & "\timec.ini", "参数", "早安", "需要推送的语句,不要有回车")
                IniWrite(@ScriptDir & "\timec.ini", "参数", "午安", "需要推送的语句,不要有回车")
                IniWrite(@ScriptDir & "\timec.ini", "参数", "晚安", "需要推送的语句,不要有回车")
                MsgBox(0,"", '读取配置,请检查并修改配置文件.',5)
        ShellExecute("timec.ini", "", @ScriptDir, "edit"); 记事本打开配置文件并允许编辑
        EndIf
        Global $tim =  (@HOUR&@MIN)
        If FileExists($time1) Then
                fas()
        Else
                fas()
        EndIf
        Sleep(5000) ;1000 等于1秒
WEnd

Func fas()
                        send("^!z");激活微信窗口快捷键
                                        send("^!z")
                                                        send("^!z");多次激活,防止被其他窗口遮挡
If $tim = $time1 Then
Local $strn = $str1
WinWaitActive("[CLASS:WeChatMainWndForPC]")
Sleep (1000)
        send("{TAB 12}")
send($unmes)
Sleep (1000)
send("{Enter}")
WinWait("[CLASS:WeChatMainWndForPC]", $unmes, 3)
        send($strn)
Sleep (2000)
send("!s")
Sleep (1000)
Else
        Sleep(1000) ;1000 等于1秒
        EndIf
        If $tim = $time2 Then
                Local $strn = $str2
WinWaitActive("[CLASS:WeChatMainWndForPC]")
Sleep (1000)
        send("{TAB 12}")
send($unmes)
Sleep (1000)
send("{Enter}")
WinWait("[CLASS:WeChatMainWndForPC]", $unmes, 3)
        send($strn)
Sleep (2000)
send("!s")
Sleep (1000)
        Else
                Sleep(1000) ;1000 等于1秒
                EndIf
                If $tim = $time3 Then
                        Local $strn = $str3
WinWaitActive("[CLASS:WeChatMainWndForPC]")
Sleep (1000)
        send("{TAB 12}")
send($unmes)
Sleep (1000)
send("{Enter}")
WinWait("[CLASS:WeChatMainWndForPC]", $unmes, 3)
        send($strn)
Sleep (2000)
send("!s")
Sleep (1000)
ext()
                Else
                          Sleep(3000) ;1000 等于1秒

EndIf

EndFunc

Func ext()
        Exit
EndFunc

;//脚本内存释放
Func _ReduceMemory()
        Local $i_PID = @AutoItPID
        If $i_PID <> -1 Then
                Local $ai_Handle = DllCall("kernel32.dll", 'int', 'OpenProcess', 'int', 0x1f0fff, 'int', False, 'int', $i_PID)
                Local $ai_Return = DllCall("psapi.dll", 'int', 'EmptyWorkingSet', 'long', $ai_Handle[0])
                DllCall('kernel32.dll', 'int', 'CloseHandle', 'int', $ai_Handle[0])
        Else
                Local $ai_Return = DllCall("psapi.dll", 'int', 'EmptyWorkingSet', 'long', -1)
        EndIf
        Return $ai_Return[0]
EndFunc   ;==>_ReduceMemory


INI文件内容
[参数]
时间1=1105
时间2=1106
时间3=1107
对象名=萱萱宝
早安=新的一天开始了,不言光阴似箭,只愿余生郑重其事。不敢奢求有锦鲤般的运气,但求长路漫漫,一切顺利,未来可期。用自己的光,照亮自己的路。早安吖!今天也要努力充实自己喔
午安=我尽力,您方便,快来华盛找花生领取福利啦
晚安=快乐的时光总是短暂的~~~花生要下线啦,感谢今天的陪伴,不要抱怨生活,不要抱怨天气,抱我,晚安,我的朋友们.




 楼主| 发表于 2020-8-3 15:35:29 | 显示全部楼层
解决了最终源码
#include <Misc.au3>
#include <Process.au3>
$g_szVersion = "自我检测1"
If WinExists($g_szVersion) Then Exit
AutoItWinSetTitle($g_szVersion)
HotKeySet("!^{x}", '_Exit') ;退出快捷键为Ctrl+ALT+x键
MsgBox(0, "", '程序已开始运行退出快捷键为Ctrl+ALT+x键', 3)
While 1
        If FileExists(@ScriptDir & "\timec.ini") Then
                Local $time1 = IniRead("timec.ini", "参数", "时间1", "time1")
                Local $time2 = IniRead("timec.ini", "参数", "时间2", "time2")
                Local $time3 = IniRead("timec.ini", "参数", "时间3", "time3")
                Local $unmes = IniRead("timec.ini", "参数", "对象名", "$unmes")
                Local $str1 = IniRead("timec.ini", "参数", "早安", "str1")
                Local $str2 = IniRead("timec.ini", "参数", "午安", "str2")
                Local $str3 = IniRead("timec.ini", "参数", "晚安", "str3")
        Else
                IniWrite(@ScriptDir & "\timec.ini", "参数", "时间1", "发送时间请用纯数字表示比如1630表示16点30分")
                IniWrite(@ScriptDir & "\timec.ini", "参数", "时间2", "发送时间请用纯数字表示比如1630表示16点30分")
                IniWrite(@ScriptDir & "\timec.ini", "参数", "时间3", "发送时间请用纯数字表示比如1630表示16点30分")
                IniWrite(@ScriptDir & "\timec.ini", "参数", "对象名", "需要发给谁,不要有特殊符号")
                IniWrite(@ScriptDir & "\timec.ini", "参数", "早安", "需要推送的语句,不要有回车")
                IniWrite(@ScriptDir & "\timec.ini", "参数", "午安", "需要推送的语句,不要有回车")
                IniWrite(@ScriptDir & "\timec.ini", "参数", "晚安", "需要推送的语句,不要有回车")
                MsgBox(0, "", '读取配置,请检查并修改配置文件.', 5)
                ShellExecute("timec.ini", "", @ScriptDir, "edit") ; 记事本打开配置文件并允许编辑
        EndIf
        If FileExists($time1) Then
                fas()
        Else
                fas()
        EndIf
        Sleep(5000) ;1000 等于1秒
WEnd

Func fas()
        Local $tim = (@HOUR & @MIN)
        For $i = 1 To 1
                If $tim = $time1 Then
                        Global $strn = $str1
                             _Wechat_AutoSend()
                        ;MsgBox(64,"测试",""&$tim&$time1&$strn&"",0)
                         Sleep(50000)
                                EndIf
                                If $tim = $time2 Then
                                        Global $strn = $str2
                              _Wechat_AutoSend()
                        ;MsgBox(64,"测试",""&$tim&$time2&$strn&"",0)
                        Sleep(50000)
                                EndIf
                                If $tim = $time3 Then
                                        Global $strn = $str3
                              _Wechat_AutoSend()
                        ;MsgBox(64,"测试",""&$tim&$time3&$strn&"",0)
                                          _exit()
                                EndIf
        Next
EndFunc   ;==>fas

Func _Exit()
        Exit
EndFunc   ;==>ext

Func _Wechat_AutoSend()
        Send("^!z")        ;激活微信窗口快捷键
        Local $hHwnd = WinWaitActive("[CLASS:WeChatMainWndForPC]")
        SendKeepActive($hHwnd)
        Send("^f")
        Send($unmes)
        Sleep(500)
        Send("{Enter}")
        SendKeepActive("")

        $hHwnd = WinWait("[CLASS:WeChatMainWndForPC]", $unmes, 3)
        SendKeepActive($hHwnd)
        Send($strn)
        Sleep(500)
        Send("!s")
        SendKeepActive("")
        Send("^!z")        ;激活微信窗口快捷键
EndFunc   ;==>_Wechat_AutoSend


发表于 2020-8-3 16:02:45 | 显示全部楼层
自动发消息吗?没看明白你的意思。
发表于 2020-8-5 07:27:48 | 显示全部楼层
明白你的意思了 源码写的很好
发表于 2020-8-5 21:13:29 | 显示全部楼层
rhci 发表于 2020-8-3 15:35
解决了最终源码
#include
#include

For $i = 1 To 1 这样和没写有什么区别
 楼主| 发表于 2020-9-7 09:58:34 | 显示全部楼层
itsky2 发表于 2020-8-5 21:13
For $i = 1 To 1 这样和没写有什么区别

强制循环1次就结束.可能有更好的办法,但这是我能想到的最好的办法了。
 楼主| 发表于 2020-9-7 10:00:48 | 显示全部楼层
经过优化的版本,比较好用,基本能达到想做的事。
#include <Misc.au3>
#include <Process.au3>
#include <WinAPI.au3>
#include <WinAPIProc.au3>
#include <WinAPIFiles.au3>
AdlibRegister("_ReduceMemory", 120000);每过120秒释放一次内存
local $key = "【自我检测多发是否重复】";检测文件是否重复运行,多个检测必须标签不同
If WinExists($key) Then
 Exit
Endif
Sleep(200)
HotKeySet("!^{x}", '_Exit') ;退出快捷键为Ctrl+ALT+x键
MsgBox(0, "", '程序已开始运行,退出快捷键为Ctrl+ALT+x键', 3)
Local $unfile = @ScriptDir & "\timec.ini"

While 1
        If FileExists($unfile) Then
        Local $tim =  @HOUR & ':' & @MIN
                file_read()
                 fas()
        Else
                file_write()
                Sleep(1000);1000 等于1秒
                _Exit()
        EndIf
WEnd

Func file_read()
        If FileExists ($unfile) Then
           Global $unmes1 = IniRead("timec.ini", "参数", "对象名1", "$unmes1")
           Global $unmes2 = IniRead("timec.ini", "参数", "对象名2", "$unmes2")
           Global  $time1 = IniRead("timec.ini", "参数", "时间1", "time1")
           Global  $time2 = IniRead("timec.ini", "参数", "时间2", "time2")
           Global  $time3 = IniRead("timec.ini", "参数", "时间3", "time3")
           Global  $time4 = IniRead("timec.ini", "参数", "时间4", "time4")
           Global  $time5 = IniRead("timec.ini", "参数", "时间5", "time5")
           Global  $time6 = IniRead("timec.ini", "参数", "时间6", "time6")
           Global  $str1 = IniRead("timec.ini", "参数", "时间1语句", "str1")
           Global  $str2 = IniRead("timec.ini", "参数", "时间2语句", "str2")
           Global  $str3 = IniRead("timec.ini", "参数", "时间3语句", "str3")
           Global  $str4 = IniRead("timec.ini", "参数", "时间4语句", "str4")
           Global  $str5 = IniRead("timec.ini", "参数", "时间5语句", "str5")
           Global  $str6 = IniRead("timec.ini", "参数", "时间6语句", "str6")
                Else
                file_write()
        EndIf
EndFunc
Func file_write()
                IniWrite(@ScriptDir & "\timec.ini", "参数", "对象名1", "需要发给谁,不要有特殊符号")
                IniWrite(@ScriptDir & "\timec.ini", "参数", "对象名2", "需要发给谁,不要有特殊符号")
                IniWrite(@ScriptDir & "\timec.ini", "参数", "时间1", "发送时间请用时:分表示比如16:30")
                IniWrite(@ScriptDir & "\timec.ini", "参数", "时间2", "发送时间请用时:分表示比如16:30")
                IniWrite(@ScriptDir & "\timec.ini", "参数", "时间3", "发送时间请用时:分表示比如16:30")
                IniWrite(@ScriptDir & "\timec.ini", "参数", "时间4", "发送时间请用时:分表示比如16:30")
                IniWrite(@ScriptDir & "\timec.ini", "参数", "时间5", "发送时间请用时:分表示比如16:30")
                IniWrite(@ScriptDir & "\timec.ini", "参数", "时间6", "发送时间请用时:分表示比如16:30")
                IniWrite(@ScriptDir & "\timec.ini", "参数", "时间1语句", "需要推送的语句,不要有回车")
                IniWrite(@ScriptDir & "\timec.ini", "参数", "时间2语句", "需要推送的语句,不要有回车")
                IniWrite(@ScriptDir & "\timec.ini", "参数", "时间3语句", "需要推送的语句,不要有回车")
                IniWrite(@ScriptDir & "\timec.ini", "参数", "时间4语句", "需要推送的语句,不要有回车")
                IniWrite(@ScriptDir & "\timec.ini", "参数", "时间5语句", "需要推送的语句,不要有回车")
                IniWrite(@ScriptDir & "\timec.ini", "参数", "时间6语句", "需要推送的语句,不要有回车")
                MsgBox(0, "", '读取配置,请检查并修改配置文件.', 5)
                ShellExecute("timec.ini", "", @ScriptDir, "edit") ; 记事本打开配置文件并允许编辑
EndFunc


Func fas()

        For $i = 1 To 1
                If $tim = $time1 Then
                         Global $strn = $str1
                          ClipPut($strn)
                          $strn = ClipGet()
                             _Wechat_AutoSend()
                        ;MsgBox(64,"测试",""&$tim&$time1&$strn&"",0)
                         Sleep(50000)
                                EndIf
                                If $tim = $time2 Then
                                        Global $strn = $str2
                          ClipPut($strn)
                          $strn = ClipGet()
                              _Wechat_AutoSend()
                        ;MsgBox(64,"测试",""&$tim&$time2&$strn&"",0)
                        Sleep(32000)
                                EndIf
                                If $tim = $time3 Then
                                        Global $strn = $str3
                                  ClipPut($strn)
                          $strn = ClipGet()
                              _Wechat_AutoSend()
                        ;MsgBox(64,"测试",""&$tim&$time3&$strn&"",0)
            Sleep(50000)
                                EndIf
                If $tim = $time4 Then
                                        Global $strn = $str4
                                          ClipPut($strn)
                          $strn = ClipGet()
                              _Wechat_AutoSend()
                        ;MsgBox(64,"测试",""&$tim&$time3&$strn&"",0)
            Sleep(50000)
                       EndIf
                       If $tim = $time5 Then
                                        Global $strn = $str5
                                          ClipPut($strn)
                          $strn = ClipGet()
                              _Wechat_AutoSend()
                        ;MsgBox(64,"测试",""&$tim&$time3&$strn&"",0)
            Sleep(50000)
                        EndIf
        If $tim = $time6 Then
                                        Global $strn = $str6
                                          ClipPut($strn)
                          $strn = ClipGet()
                              _Wechat_AutoSend()
                        ;MsgBox(64,"测试",""&$tim&$time3&$strn&"",0)
                                          _exit()
                                EndIf
        Next
EndFunc   ;==>fas
Func _Exit()
        Exit
EndFunc   ;==>ext

Func _Wechat_AutoSend()
        Send("^!z")        ;激活微信窗口快捷键
        Local $hHwnd = WinWaitActive("[CLASS:WeChatMainWndForPC]")
        SendKeepActive($hHwnd)
        Send("^f")
        Send($unmes1)
        Sleep(500)
        Send("{Enter}")
        SendKeepActive("")
        $hHwnd = WinWait("[CLASS:WeChatMainWndForPC]", $unmes1, 3)
        SendKeepActive($hHwnd)
        ;Send($strn)
        Send("^v")
        Sleep(1000)
        Send("!s")
        SendKeepActive("")

        Send("^f")
        Send($unmes2)
        Sleep(1000)
        Send("{Enter}")
        SendKeepActive("")
        $hHwnd = WinWait("[CLASS:WeChatMainWndForPC]", $unmes2, 3)
        SendKeepActive($hHwnd)
        ;Send($strn)
        Send("^v")
        Sleep(1000)
        Send("!s")
        SendKeepActive("")

        Send("^!z")        ;激活微信窗口快捷键
EndFunc   ;==>_Wechat_AutoSend

Func _ReduceMemory();//脚本内存释放
        Local $i_PID = @AutoItPID
        If $i_PID <> -1 Then
                Local $ai_Handle = DllCall("kernel32.dll", 'int', 'OpenProcess', 'int', 0x1f0fff, 'int', False, 'int', $i_PID)
                Local $ai_Return = DllCall("psapi.dll", 'int', 'EmptyWorkingSet', 'long', $ai_Handle[0])
                DllCall('kernel32.dll', 'int', 'CloseHandle', 'int', $ai_Handle[0])
        Else
                Local $ai_Return = DllCall("psapi.dll", 'int', 'EmptyWorkingSet', 'long', -1)
        EndIf
        Return $ai_Return[0]
EndFunc   ;==>_ReduceMemory
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-3-29 01:57 , Processed in 0.072205 second(s), 19 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表