首页 技术 正文
技术 2022年11月6日
0 收藏 512 点赞 1,010 浏览 1890 个字

因为是检测窗口实现的,所以要求设置会话窗口自动弹出,而且看完消息就把QQ消息窗口关掉。。。

虚拟机端

#! /usr/bin/env python
# -*- coding: utf-8 -*-from win32gui import *
import time
import socketHOST = '192.168.0.126'#宿主机IP地址
PORT = 8001def get_QQ_titles(hwnd, mouse):
if IsWindow(hwnd) and IsWindowEnabled(hwnd) and IsWindowVisible(hwnd):
if GetClassName(hwnd) == 'TXGuiFoundation': # TXGuiFoundation 是所有QQ窗口的类名
text=GetWindowText(hwnd)
if text:
current_QQ_titles.add(text)def send_message(): # 通知宿主机
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((HOST, PORT))
s.send('new_msg')
data = s.recv(10)
print datalast_QQ_titles = set() # 上一次所有可见QQ窗口的 title 字符串集合
current_QQ_titles = set() # 当前所有可见QQ窗口的 title 字符串集合
last_foreground_window_class_name = '' # 上一个 foreground window 的类名
while True:
current_QQ_titles = set()
EnumWindows(get_QQ_titles, 0) # 遍历当前可见的QQ窗口
try:
foreground_window = GetForegroundWindow()
foreground_window_text = GetWindowText(foreground_window)
foreground_window_class_name = GetClassName(foreground_window)
except Exception,e:
print('catch exception')
if last_QQ_titles != current_QQ_titles \
and len(last_QQ_titles) < len(current_QQ_titles) \
and (last_foreground_window_class_name != foreground_window_class_name \
or (last_foreground_window_class_name == foreground_window_class_name \
and foreground_window_text != 'QQ')):
print 'got new message'
send_message()
last_QQ_titles = current_QQ_titles
last_foreground_window_class_name = foreground_window_class_name
time.sleep(1)

宿主机端

 #encoding=utf-8
import Tkinter as tk
import socket def create_message_dialog():
top = tk.Tk()
top.title("QQ Message")
top.geometry('400x400')
labelHello = tk.Label(top, text = "You've got new QQ messages.")
labelHello.pack()
top.mainloop() HOST = '192.168.0.126'
PORT = 8001 s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind((HOST, PORT))
s.listen(1) print 'Server start at: %s:%s' %(HOST, PORT)
print 'wait for connection...' while True:
conn, addr = s.accept()
print 'Connected by ', addr
data = conn.recv(10)
print data
if data=='new_msg':
create_message_dialog()
conn.send("recv")
conn.close()

END

2017.8.17 19:58

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,487
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,903
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,736
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,486
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:8,126
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:5,287