最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

如何用python 實(shí)現(xiàn)老板鍵功能

 更新時(shí)間:2021年03月15日 11:41:55   作者:可愛的黑精靈  
這篇文章主要介紹了python 開發(fā)老板鍵功能的方法,幫助大家更好的理解和學(xué)習(xí)使用python,感興趣的朋友可以了解下

主要實(shí)現(xiàn)目標(biāo):為多個(gè)指定的程序?qū)崿F(xiàn)統(tǒng)一的老板鍵,一鍵隱藏多個(gè)指定的應(yīng)用程序的窗口及任務(wù)欄。

1.獲取所有頂層窗口

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]

2.手動(dòng)選擇需要設(shè)置老板鍵的程序

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()

3.隱藏或顯示選中程序

# 通過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)

4.設(shè)置顯示隱藏快捷鍵

這里設(shè)置F7顯示,F(xiàn)8隱藏,F(xiàn)12中止

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()

# 開啟監(jiān)聽
pythoncom.PumpMessages()

5.最終效果

以上就是python 老板鍵功能的實(shí)現(xiàn)步驟的詳細(xì)內(nèi)容,更多關(guān)于python 老板鍵功能的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!

相關(guān)文章

最新評(píng)論

鸡泽县| 弥渡县| 喀喇| 三门峡市| 深泽县| 高邑县| 廊坊市| 龙门县| 曲靖市| 宜良县| 班戈县| 商洛市| 米脂县| 灵寿县| 思南县| 雅江县| 丘北县| 山阳县| 新干县| 崇明县| 红桥区| 泾源县| 玛多县| 绥德县| 平远县| 海林市| 嘉荫县| 长宁县| 重庆市| 德化县| 永修县| 涞水县| 合阳县| 紫金县| 嵊州市| 南投市| 三亚市| 焉耆| 惠安县| 石台县| 洪洞县|