这篇文章主要介绍了怎么用python实现老板键功能,具有一定借鉴价值,感兴趣的朋友可以参考下,希望大家阅读完这篇文章之后大有收获,下面让小编带着大家一起了解一下。
import win32gui
hwnd_title = dict()
def get_all_hwnd(hwnd, mouse):
# 判断句柄是否为窗口、窗口是否允许输入、窗口是否可视
if win32gui.IsWindow(hwnd) and win32gui.IsWindowEnabled(hwnd) and win32gui.IsWindowVisible(hwnd):
hwnd_title.update({hwnd: win32gui.GetWindowText(hwnd)})
# EnumWindows枚举所有顶层窗口
win32gui.EnumWindows(get_all_hwnd, 0)
# 打印出所有窗口名不为空的窗口
for key in list(hwnd_title):
if hwnd_title[key] is "":
del hwnd_title[key]
import tkinter as tk
root = tk.Tk()
root.geometry("800x400")
# 列表显示所有顶层窗口
listBox = tk.Listbox(root, selectmode="multiple")
listBox.pack(side="left", expand="yes", fill="both")
for i, j in hwnd_title.items():
if j is not "":
listBox.insert("end", str(i) + ":" + j)
bt = tk.Button(root, text='选择')
bt.pack()
root.mainloop()
# 通过GetWindowRect方法获取隐藏前的窗口位置及尺寸信息
left, top, right, bottom = win32gui.GetWindowRect()
def close_windows(aimLists):
for k in aimLists:
# 隐藏程序窗口
win32gui.SetWindowPos(lists[k][0], 0, 0, 0, 0, 0, SWP_HIDEWINDOW)
def open_windows(aimLists):
for k in aimLists:
# 显示程序窗口
t = lists[k]
win32gui.SetWindowPos(t['hwnd'], 0, t['left'], t['top'], t['right'] - t['left'], t['bottom'] - t['top'],
SWP_SHOWWINDOW)
这里设置F7显示,F8隐藏,F12中止
import PyHook3
import pythoncom
def onKeyboardEvent(event):
key = event.Key
if key == "F7":
close_windows(aimLists)
if key == "F8":
open_windows(aimLists)
if key == "F12":
win32gui.PostQuitMessage(0)
return True
hm = PyHook3.HookManager()
hm.KeyDown = onKeyboardEvent
hm.HookKeyboard()
# 开启监听
pythoncom.PumpMessages()
感谢你能够认真阅读完这篇文章,希望小编分享的“怎么用python实现老板键功能”这篇文章对大家有帮助,同时也希望大家多多支持亿速云,关注亿速云行业资讯频道,更多相关知识等着你来学习!
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。