AHK获取微信联系人
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;作者:Kawvin大神;修改:Space
;更新于:2017-12-30-21-45
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Process, Priority,,high ;脚本高优先级#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
#NoTrayIcon ;隐藏托盘图标
#SingleInstance force ;单脚本运行
;~ #Warn All, Off
OnExit, OnExit
SendMode Input ;Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ;设置工作目录
SetTitleMatchMode,2 ;设置WinWait等命令,匹配包含指定的 WinTitle 的窗口标题,精确匹配
ComObjError(0) ;禁用 COM 错误通告
SetBatchLines -1
CoordMode, mouse, Client
global flag := 1
global MyINI:=A_ScriptDir . "\微信常用联系人列表.ini"
global MyWeRecArray:={}
IniRead,MyWeChatTo,%MyINI%,微信收件人
StringReplace,MyWeChatTo,MyWeChatTo,`n,|,All
MyWeRecArray:=StrSplit(MyWeChatTo,"|")
global bgDir:=A_ScriptDir "\bing"
IfNotExist, %MyINI%
FileAppend, ; 这里需要逗号.
(
[通用设置]
微信发送热键=!w
微信路径=D:\Program Files\Internet\Tencent\WeChat\WeChat.exe
原始X坐标=376
原始Y坐标=115
原始宽度=1075
原始高度=811
[微信收件人]
--[家庭]--
爸爸
妈妈
哥哥
--[工作]--
李大新
路文文
--[供应商]--
江大联盛胡瑛
长沙天骄陈总
--[朋友]--
李平
李红钢
), %MyINI%
;~ SetTimer, checks, on, 500
return
GetPID(exe){ ;一个自定义函数,根据自定义函数的返回值作为#if成立依据
Process, Exist,% exe
return ErrorLevel
}
F22::
~!w:: ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;请把微信快捷键设置为alt+w
gosub DOCKED
return
#If flag=1
~^!w::
if GetPID("WeChat.exe")=0
{
Run, D:\Program Files\Internet\Tencent\WeChat\WeChat.exe
WinWaitActive ahk_class WeChatLoginWndForPC
Sleep 200
Send {Enter}
}else{
flag := 0
gosub DOCKED
}
return
#IfWinActive ahk_class WeChatMainWndForPC
~!w:: ;WeChatMainWndForPC微信
gosub OnHostDeath
Gui, Destroy
return
#If
DOCKED:
WinWaitActive ahk_class WeChatMainWndForPC
WinGet, nPID, PID, A ;必须配置,DocK的host程序ID
Dock_HostID := WinExist("ahk_pid " . nPID) ;检测主程序退出时调用的sub
Dock_OnHostDeath := "OnHostDeath"
;~ Gui +LastFound -Caption -SysMenu -Theme +ToolWindow +hwndClient1ID
Gui -Caption +hwndClient1ID
Gui ,Font, s12
Gui ,Add,text , x15 y10 w100 gMySub_SendFile_WeChat ,传输助手
Gui ,Font
loop , % MyWeRecArray.Length()
{
Gui ,Font, s12
FF:=SubStr(MyWeRecArray[A_index],0,1)
if (FF="-")
Gui ,Add, text , x15 yp+28 cRed Disabled w100 gMySub_SendFile_WeChat,% MyWeRecArray[A_index]
else
Gui ,Add, text , x15 yp+28 w100 gMySub_SendFile_WeChat,% MyWeRecArray[A_index]
Gui ,Font
}
Gui Show, NoActivate, 微信联系人列表
dock(Client1ID, "x(0.983,0,) y(0,0.029,) t ") ;调整位置————————————————————————
return
MySub_SendFile_WeChat:
Gui,Submit,NoHide
LXR:=A_GuiControl
WinActivate,ahk_class WeChatMainWndForPC
WinWaitActive ahk_class WeChatMainWndForPC
ControlClick, x114 y45 ; , 微信,,,, Pos ;相对于窗体左上角的相对位置点击
;删除已有数据
;~ SendInput,^a
;~ SendInput,{del}
if (LXR="传输助手")
{
SendRaw 文件传输助手
}
else {
SendRaw % LXR
}
Sleep, 900 ;调整时间,太短失效————————————————————————
SendInput,{Enter}
return
GuiClose:
ExitApp
OnExit:
;调用dock的退出
Dock_Shutdown()
;关闭所有相关的程序
;退出程序
ExitApp
return
OnHostDeath:
;销毁dock
Dock_Shutdown()
; Dock_Toggle(false)
Gui, Destroy
return
Dock(pClientID, pDockDef="", reset=0) { ;Reset is internal parameter, used by Dock_Shutdown
local cnt, new, cx, cy, hx, hY, t, hP
static init=0, idDel, classes="x|y|w|h"
if (reset) ;Used by Dock Shutdown to reset the function
return init := 0
if !init
Dock_aClient_0_ := 0
cnt := Dock_aClient_0_
;remove dock client ?
if (pDockDef="-") and (Dock_%pClientID%){
idDel := Dock_%pClientID%
loop, parse, classes, |
loop, 3
Dock_%pClientID%_%A_LoopField%%A_Index% := ""
Dock_%pClientID% := ""
Dock_aClient_%idDel%_ := Dock_aClient_%cnt%_, Dock_aClient_%cnt%_ := "", Dock_aClient_0_--
return "OK - Remove"
}
if pDockDef =
{
WinGetPos hX, hY,,, ahk_id %Dock_HostID%
WinGetPos cX, cY,,, ahk_id %pClientID%
pDockDef := "x(0,0," cX - hX ") y(0,0," cY - hY ")"
}
loop, parse, pDockDef, %A_Space%%A_Tab%
if (A_LoopField != "") {
t := A_LoopField, c := SubStr(t,1,1)
if c not in x,y,w,h,t
return "ERR: Bad dock definition"
if c = t
{
Dock_%pClientID%_t := 1
}
else {
t := SubStr(t,3,-1)
StringReplace, t, t,`,,|,UseErrorLevel
t .= !ErrorLevel ? "||" : (ErrorLevel=1 ? "|" : "")
loop, parse, t,|,%A_Space%%A_Tab%
Dock_%pClientID%_%c%%A_Index% := A_LoopField ? A_LoopField : 0
}
}
if !Dock_%pClientID% {
Dock_%pClientID% := ++cnt,
Dock_aClient_%cnt%_ := pClientId
Dock_aClient_0_++
}
If !init {
init++, Dock_hookProcAdr := RegisterCallback("Dock_HookProc")
Dock_Toggle(true)
}
Dock_Update()
return "OK"
}
Dock_Shutdown() {
local cID
Dock_Toggle(false)
DllCall("GlobalFree", "UInt", Dock_hookProcAdr), Dock_hookProcAdr := ""
Dock(0,0,1)
loop, % Dock_aClient_0_
{
cId := Dock_aClient_%A_Index%_, Dock_aClient_%A_Index%_ := ""
Dock_%cID% := ""
loop, 10
Dock_%cID%_%A_Index% := ""
}
}
Dock_Toggle( enable="" ) {
global
if Dock_hookProcAdr =
return "ERR - Dock must be loaded."
if enable =
enable := !Dock_hHook1
else if (enable && Dock_hHook1)
return "ERR - Dock already enabled"
if !enable
API_UnhookWinEvent(Dock_hHook1), API_UnhookWinEvent(Dock_hHook2), API_UnhookWinEvent(Dock_hHook3), Dock_hHook3 := Dock_hHook1 := Dock_hHook2 := ""
else {
Dock_hHook1 := API_SetWinEventHook(3,3,0,Dock_hookProcAdr,0,0,0) ; EVENT_SYSTEM_FOREGROUND
Dock_hHook2 := API_SetWinEventHook(0x800B,0x800B,0,Dock_hookProcAdr,0,0,0) ; EVENT_OBJECT_LOCATIONCHANGE
Dock_hHook3 := API_SetWinEventHook(0x8002,0x8003,0,Dock_hookProcAdr,0,0,0) ; EVENT_OBJECT_SHOW, EVENT_OBJECT_HIDE
if !(Dock_hHook1 && Dock_hHook2 && Dock_hHook3) { ;some of them failed, unregister everything
API_UnhookWinEvent(Dock_hHook1), API_UnhookWinEvent(Dock_hHook2), API_UnhookWinEvent(Dock_hHook3)
return "ERR - Hook failed"
}
Dock_Update()
}
return enable
}
;==================================== INTERNAL ======================================================
Dock_Update() {
local hX, hY, hW, hh, W, H, X, Y, cx, cy, cw, ch, fid, wd, cid
static gid=0 ;fid & gid are function id and global id. I use them to see if the function interupted itself.
wd := A_WinDelay
SetWinDelay, -1
fid := gid += 1
WinGetPos hX, hY, hW, hH, ahk_id %Dock_HostID%
loop, % Dock_aClient_0_
{
cId := Dock_aClient_%A_Index%_
WinGetPos cX, cY, cW, cH, ahk_id %cID%
W := Dock_%cId%_w1*hW + Dock_%cId%_w2, H := Dock_%cId%_h1*hH + Dock_%cId%_h2
X := hX + Dock_%cId%_x1*hW + Dock_%cId%_x2* (W ? W : cW) + Dock_%cId%_x3
Y := hY + Dock_%cId%_y1*hH + Dock_%cId%_y2* (H ? H : cH) + Dock_%cId%_y3
if (fid != gid)
break
if dock_resetT
{
dock_resetT := false
DllCall("SetWindowLong", "uint", cId, "int", -8, "uint", 0)
}
DllCall("SetWindowPos", "uint", cId, "uint", 0, "uint", X ? X : cX, "uint", Y ? Y : cY, "uint", W ? W : cW, "uint", H ? H :cH, "uint", 1044)
}
SetTimer, Dock_SetZOrder, -80
SetWinDelay, %wd%
}
Dock_SetZOrder:
exists := WinExist("ahk_id " Dock_HostID), active := WInExist("A") = Dock_HostId
loop, % Dock_aClient_0_
{
_ := Dock_aClient_%A_Index%_, _ := Dock_%_%_t
if !_
DllCall("SetWindowPos", "uint", Dock_aClient_%A_Index%_, "uint", Dock_HostID, "uint", 0, "uint", 0, "uint", 0, "uint", 0, "uint", 19 | 0x4000 | 0x40)
else {
_ := DllCall("GetWindowLong", "uint", Dock_aClient_%A_Index%_, "int", -8)
if !_ and exists
{
dock_resetT := true
DllCall("SetWindowLong", "uint", Dock_aClient_%A_Index%_, "int", -8, "uint", Dock_HostId)
}
DllCall("SetWindowPos", "uint", Dock_aClient_%A_Index%_, "uint"
, active ? 0 : DllCall("GetWindow", "uint", Dock_HostId, "uint", 3) ;hwndprev
, "uint", 0, "uint", 0, "uint", 0, "uint", 0, "uint", 0x40 | 19 | 0x4000) ;SWP_SHOWWINDOW ..., no activate
}
}
return
Dock_SetZOrder_OnClientFocus:
res := DllCall("SetWindowPos", "uint", Dock_HostID, "uint", Dock_AClient, "uint", 0, "uint", 0, "uint", 0, "uint", 0, "uint", 19)
loop, % Dock_aClient_0_
{
_ := Dock_aClient_%A_Index%_, _ := Dock_%_%_t
if !_
DllCall("SetWindowPos", "uint", Dock_aClient_%A_Index%_, "uint", Dock_HostID, "uint", 0, "uint", 0, "uint", 0, "uint", 0, "uint", 19)
}
return
Dock_HookProc(hWinEventHook, event, hwnd, idObject, idChild, dwEventThread, dwmsEventTime ) {
local e, cls, style
if idObject or idChild
return
WinGet, style, Style, ahk_id %hwnd%
if (style & 0x40000000) ;RETURN if hwnd is child window, for some reason idChild may be 0 for some children ?!?! ( I hate ms )
return
if (event = 3)
{
loop, % Dock_aClient_0_
if (hwnd = Dock_aClient_%A_Index%_){
Dock_AClient := hwnd
gosub Dock_SetZOrder_OnClientFocus
return
}
}
If (hwnd != Dock_HostID){
if !WinExist("ahk_id " Dock_HostID) && IsLabel(Dock_OnHostDeath)
{
Dock_Toggle(false)
gosub %Dock_OnHostDeath%
loop, % Dock_aClient_0_
DllCall("ShowWindow", "uint", Dock_aClient_%A_Index%_, "uint", 0)
}
return
}
if event in 32770,32771
{
e := (event - 32771) * -5
loop, % Dock_aClient_0_
DllCall("ShowWindow", "uint", Dock_aClient_%A_Index%_, "uint", e)
}
Dock_Update()
}
Dock_Update:
Dock_Update()
return
API_SetWinEventHook(eventMin, eventMax, hmodWinEventProc, lpfnWinEventProc, idProcess, idThread, dwFlags) {
DllCall("CoInitialize", "uint", 0)
return DllCall("SetWinEventHook", "uint", eventMin, "uint", eventMax, "uint", hmodWinEventProc, "uint", lpfnWinEventProc, "uint", idProcess, "uint", idThread, "uint", dwFlags)
}
API_UnhookWinEvent( hWinEventHook ) {
return DllCall("UnhookWinEvent", "uint", hWinEventHook)
}
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。

