如何用python 實(shí)現(xiàn)老板鍵功能
主要實(shí)現(xiàn)目標(biāo):為多個(gè)指定的程序?qū)崿F(xiàn)統(tǒng)一的老板鍵,一鍵隱藏多個(gè)指定的應(yīng)用程序的窗口及任務(wù)欄。
1.獲取所有頂層窗口import win32guihwnd_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 tkroot = 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()
# 通過(guò)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 PyHook3import pythoncomdef onKeyboardEvent(event): key = event.Key if key == 'F7': close_windows(aimLists) if key == 'F8': open_windows(aimLists) if key == 'F12': win32gui.PostQuitMessage(0) return Truehm = PyHook3.HookManager()hm.KeyDown = onKeyboardEventhm.HookKeyboard()# 開(kāi)啟監(jiān)聽(tīng)pythoncom.PumpMessages()5.最終效果
以上就是python 老板鍵功能的實(shí)現(xiàn)步驟的詳細(xì)內(nèi)容,更多關(guān)于python 老板鍵功能的資料請(qǐng)關(guān)注好吧啦網(wǎng)其它相關(guān)文章!
相關(guān)文章:
1. ASP基礎(chǔ)知識(shí)VBScript基本元素講解2. Python requests庫(kù)參數(shù)提交的注意事項(xiàng)總結(jié)3. ajax請(qǐng)求添加自定義header參數(shù)代碼4. IntelliJ IDEA導(dǎo)入jar包的方法5. Gitlab CI-CD自動(dòng)化部署SpringBoot項(xiàng)目的方法步驟6. Kotlin + Flow 實(shí)現(xiàn)Android 應(yīng)用初始化任務(wù)啟動(dòng)庫(kù)7. 詳談ajax返回?cái)?shù)據(jù)成功 卻進(jìn)入error的方法8. python操作mysql、excel、pdf的示例9. vue-electron中修改表格內(nèi)容并修改樣式10. python爬蟲(chóng)學(xué)習(xí)筆記之pyquery模塊基本用法詳解
