如何用python 實現(xiàn)老板鍵功能
更新時間:2021年03月15日 11:41:55 作者:可愛的黑精靈
這篇文章主要介紹了python 開發(fā)老板鍵功能的方法,幫助大家更好的理解和學習使用python,感興趣的朋友可以了解下
主要實現(xiàn)目標:為多個指定的程序實現(xiàn)統(tǒng)一的老板鍵,一鍵隱藏多個指定的應用程序的窗口及任務欄。
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.手動選擇需要設置老板鍵的程序
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.設置顯示隱藏快捷鍵
這里設置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 老板鍵功能的實現(xiàn)步驟的詳細內容,更多關于python 老板鍵功能的資料請關注腳本之家其它相關文章!
相關文章
詳解用pyecharts Geo實現(xiàn)動態(tài)數(shù)據熱力圖城市找不到問題解決
這篇文章主要介紹了詳解用pyecharts Geo實現(xiàn)動態(tài)數(shù)據熱力圖城市找不到問題解決,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2019-06-06
Python集成C#實現(xiàn)界面操作下載文件功能的全過程
使用腳本進行下載的需求很常見,下面這篇文章主要給大家介紹了關于Python集成C#實現(xiàn)界面操作下載文件功能的相關資料,文中通過實例代碼介紹的非常詳細,需要的朋友可以參考下2022-03-03
Python如何使用struct.unpack處理二進制文件
這篇文章主要介紹了Python如何使用struct.unpack處理二進制文件問題,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2024-02-02
python requests更換代理適用于IP頻率限制的方法
今天小編就為大家分享一篇python requests更換代理適用于IP頻率限制的方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2019-08-08

