主頁 > 知識庫 > 如何用python 實現(xiàn)老板鍵功能

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

熱門標簽:硅谷的囚徒呼叫中心 Win7旗艦版 電話運營中心 百度AI接口 語音系統(tǒng) 企業(yè)做大做強 客戶服務(wù) 呼叫中心市場需求

主要實現(xiàn)目標:為多個指定的程序?qū)崿F(xiàn)統(tǒng)一的老板鍵,一鍵隱藏多個指定的應(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.手動選擇需要設(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 老板鍵功能的實現(xiàn)步驟的詳細內(nèi)容,更多關(guān)于python 老板鍵功能的資料請關(guān)注腳本之家其它相關(guān)文章!

您可能感興趣的文章:
  • python爬蟲開發(fā)之使用python爬蟲庫requests,urllib與今日頭條搜索功能爬取搜索內(nèi)容實例
  • Python開發(fā)之基于模板匹配的信用卡數(shù)字識別功能
  • Python使用百度翻譯開發(fā)平臺實現(xiàn)英文翻譯為中文功能示例
  • 使用Python來開發(fā)微信功能
  • Python開發(fā)之快速搭建自動回復(fù)微信公眾號功能

標簽:喀什 安康 海南 崇左 山西 山西 濟南 長沙

巨人網(wǎng)絡(luò)通訊聲明:本文標題《如何用python 實現(xiàn)老板鍵功能》,本文關(guān)鍵詞  ;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請?zhí)峁┫嚓P(guān)信息告之我們,我們將及時溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 收縮
    • 微信客服
    • 微信二維碼
    • 電話咨詢

    • 400-1100-266