国产成人精品亚洲777人妖,欧美日韩精品一区视频,最新亚洲国产,国产乱码精品一区二区亚洲

您的位置:首頁(yè)技術(shù)文章
文章詳情頁(yè)

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

瀏覽:3日期:2022-06-24 18:27:05

主要實(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]

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

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

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

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

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 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()# 開啟監(jiān)聽pythoncom.PumpMessages()5.最終效果

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

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

標(biāo)簽: Python 編程
相關(guān)文章:
主站蜘蛛池模板: 彭泽县| 左云县| 桐城市| 小金县| 黄石市| 沐川县| 广德县| 荔波县| 莱阳市| 攀枝花市| 昌江| 东阿县| 永靖县| 内黄县| 平武县| 汝城县| 广西| 清苑县| 新巴尔虎左旗| 子洲县| 台湾省| 当雄县| 湖北省| 汾阳市| 昭觉县| 灵山县| 弥渡县| 德惠市| 东乡| 普陀区| 彭阳县| 桃源县| 台中县| 鄄城县| 广汉市| 府谷县| 拜城县| 吉木乃县| 兰溪市| 景德镇市| 班戈县|