同事们组建了个聊天群,头衔是白痴,傻瓜啥的,为了争取升级为逗比,大家使劲刷,手工刷多没意思啊,做了个机器人跟屁虫,等离开座位就可以开起来自动刷…不怕垫底了,哈哈.

实现功能:

  • 查找指定名称的窗口;

  • 定时复制最后一行聊天记录,如果和上一次不一样,则粘贴发送

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import win.ui;
import win.ui.atom;
import winex;
import winex.key;
import winex.mouse;
import win.clip;
/*DSG{{*/
mainForm = win.form(text="QQ聊天跟屁虫";right=489;bottom=150;max=false)
mainForm.add(
button={cls="button";text="启动跟屁虫模式";left=27;top=87;right=230;bottom=121;font=LOGFONT(name='微软雅黑';h=-16);z=2};
button2={cls="button";text="停止跟屁虫模式";left=260;top=87;right=463;bottom=121;font=LOGFONT(name='微软雅黑';h=-16);z=4};
edit={cls="edit";left=125;top=28;right=462;bottom=54;db=1;dl=1;dr=1;dt=1;edge=1;font=LOGFONT(name='微软雅黑';h=-14);multiline=1;z=1};
static={cls="static";text="聊天窗名称";left=31;top=30;right=117;bottom=53;font=LOGFONT(name='微软雅黑';h=-16);transparent=1;z=3}
)
/*}}*/

mainForm.button2.oncommand = function(id,event){

mainForm.killtimer(tmid)//移除此定时器

}

var atom,hwnd/*冲突窗口的句柄,该函数会自动激活此窗口*/ = mainForm.atom("sobaigu_qqchat");
if(!atom){
/*为窗口设置原子值可以避免一个程序重复运行多个实例*/
win.quitMessage(); return;
}

mainForm.button.oncommand = function(id,event){
mainForm.killtimer(tmid)//移除此定时器

var chatname = mainForm.edit.text;
if(chatname == ""){
win.msgboxTimeout("请输入聊天窗口名称",,2000);
return ;

}

//获取剪贴板内容
clicp1 = win.clip.read();
//mainForm.msgbox(clicp1);

//定时器
tmid = mainForm.addtimer(
1000/*毫秒*/,
function(hwnd,msg,id,tick){//定时执行代码
//查找指定的窗口并激活
wintitle = winex.findActivate( chatname );
if (wintitle == false){
win.msgboxTimeout("未找到该窗口,特殊符号需在前面加\进行转义",,2000);
return ;
}

//获取最后一行聊天记录左坐标并点击复制
var x,y = win.toClient(wintitle,x,y);
winex.mouse.click(wintitle,45,345);
key.combine("CTRL","C");

clicp2 = win.clip.read();
//mainForm.msgbox(clicp2);

if(clicp2 != clicp1){
key.combine("CTRL","V");
key.press("ENTER");//回车发送

clicp1 = clicp2;
win.delay(1500);

//处理专属表情报错问题
errmsg, ,qqcname = winex.findExists("提示",,"TXGuiFoundation");
if(errmsg == true){
winex.close(errmsg);//关闭窗口
key.combine("CTRL","A");
key.press("BACK");
}
}

//mainForm.settimer(id,2000)//重新设定时间间隔
}
);

}

mainForm.show();
win.loopMessage();