吾爱破解 - 52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 3486|回复: 20
收起左侧

[原创工具] python任意窗口老板键

  [复制链接]
tuoluo348 发表于 2024-5-4 08:50
本帖最后由 tuoluo348 于 2024-5-20 20:07 编辑

以前需要老板键功能,百度下载了好几个 还中了病毒 后来我就用python写了一个
在列表选择要隐藏的窗口后点击下面的选中按钮
F7显示/隐藏 F12退出软件
添加自定义快捷键 支持组合键(ctrl,alt,shift)
输入自定义快捷键后点击设置快捷键按钮 然后选择要隐藏的窗口 点击选中按钮

[Python] 纯文本查看 复制代码
001
002
003
004
005
006
007
008
009
010
011
012
013
014
015
016
017
018
019
020
021
022
023
024
025
026
027
028
029
030
031
032
033
034
035
036
037
038
039
040
041
042
043
044
045
046
047
048
049
050
051
052
053
054
055
056
057
058
059
060
061
062
063
064
065
066
067
068
069
070
071
072
073
074
075
076
077
078
079
080
081
082
083
084
085
086
087
088
089
090
091
092
093
094
095
096
097
098
099
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
import win32gui
import win32con
import time
from tkinter import *
import pyWinhook as PyHook3
import pythoncom
 
# 全局变量定义
lst = []
hwnd_title = dict()
key_states = {"Ctrl": False, "Alt": False, "Shift": False}
toggle_key = "F7"
exit_key = "F12"
 
# 获取所有窗口句柄和标题
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)})
 
# 关闭窗口
def close_windows(aimLists):
    win32gui.ShowWindow(int(aimLists), win32con.SW_HIDE)
 
# 打开窗口
def open_windows(aimLists):
    win32gui.ShowWindow(int(aimLists), win32con.SW_SHOW)
 
# 键盘事件处理函数
n = 0
def onKeyboardEvent(event):
    global n, toggle_key, exit_key
     
    key = event.Key
    if key == "Lcontrol" or key == "Rcontrol":
        key_states["Ctrl"] = event.MessageName == "key down"
    elif key == "Lmenu" or key == "Rmenu":
        key_states["Alt"] = event.MessageName == "key down"
    elif key == "Lshift" or key == "Rshift":
        key_states["Shift"] = event.MessageName == "key down"
 
    if event.MessageName == "key down":
        # 检查切换窗口的快捷键
        if check_key_combination(event, toggle_key):
            n += 1
            if n % 2 != 0:
                for i in range(len(lst)):
                    close_windows(lst[i].split(',')[0])
            else:
                for i in range(len(lst)):
                    open_windows(lst[i].split(',')[0])
         
        # 检查退出的快捷键
        if check_key_combination(event, exit_key):
            win32gui.PostQuitMessage(0)
     
    return True
 
# 检查当前键是否匹配定义的快捷键
def check_key_combination(event, key_combination):
    keys = key_combination.lower().split("+")
    if len(keys) == 1:
        return event.Key.lower() == keys[0]
    elif len(keys) == 2:
        return key_states[keys[0].capitalize()] and event.Key.lower() == keys[1]
    elif len(keys) == 3:
        return key_states[keys[0].capitalize()] and key_states[keys[1].capitalize()] and event.Key.lower() == keys[2]
    return False
 
# 选择窗口的回调函数
def select_windows():
    for i in range(listb.size()):
        if listb.select_includes(i):
            lst.append(listb.get(i))
    root.destroy()
 
# 设置快捷键的回调函数
def set_shortcuts():
    global toggle_key, exit_key
    toggle_key = entry_toggle_key.get()
    exit_key = entry_exit_key.get()
 
# 获取所有窗口
win32gui.EnumWindows(get_all_hwnd, 0)
for key in list(hwnd_title):
    if hwnd_title[key] == "":
        del hwnd_title[key]
 
# 创建Tkinter窗口
root = Tk()
root.geometry("600x400")
 
# 创建窗口列表框
listb = Listbox(root, selectmode=MULTIPLE, width=80, height=10)
for i, j in hwnd_title.items():
    if j != "":
        listb.insert("end", str(i) + ',' + j)
listb.pack()
 
# 创建选择按钮
button_select = Button(root, text="选中", command=select_windows)
button_select.pack()
 
# 创建文本框和标签用于设置快捷键
label_toggle_key = Label(root, text="显示/隐藏的快捷键(ctrl,alt,shift)")
label_toggle_key.pack()
entry_toggle_key = Entry(root)
entry_toggle_key.pack()
entry_toggle_key.insert(0, "F7")
 
label_exit_key = Label(root, text="退出的快捷键(ctrl,alt,shift)")
label_exit_key.pack()
entry_exit_key = Entry(root)
entry_exit_key.pack()
entry_exit_key.insert(0, "F12")
 
# 创建设置快捷键的按钮
button_set_shortcuts = Button(root, text="设置快捷键", command=set_shortcuts)
button_set_shortcuts.pack()
 
# 挂钩键盘事件
hm = PyHook3.HookManager()
hm.KeyDown = onKeyboardEvent
hm.KeyUp = onKeyboardEvent
hm.HookKeyboard()
 
root.mainloop()
 
# 开启监听
pythoncom.PumpMessages()



下载地址:https://wwf.lanzouq.com/ipHw71zagoyb
image.png
Snipaste_2024-05-20_20-02-57.png

免费评分

参与人数 3吾爱币 +9 热心值 +2 收起 理由
l12312329 + 1 + 1 谢谢@Thanks!
caszx + 1 感谢发布原创作品,吾爱破解论坛因你更精彩!
风之暇想 + 7 + 1 感谢发布原创作品,吾爱破解论坛因你更精彩!

查看全部评分

本帖被以下淘专辑推荐:

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

头像被屏蔽
sxzswx 发表于 2024-5-6 04:37
提示: 作者被禁止或删除 内容自动屏蔽
lmpgone 发表于 2024-5-6 09:26
这个只能隐藏窗口 有没有能隐藏程序的 开机自启,右下角的图标也隐藏的
W239179 发表于 2024-5-6 10:56
 楼主| tuoluo348 发表于 2024-5-6 10:56
lmpgone 发表于 2024-5-6 09:26
这个只能隐藏窗口 有没有能隐藏程序的 开机自启,右下角的图标也隐藏的

这个没有研究过
l12312329 发表于 2024-5-6 12:46
lmpgone 发表于 2024-5-6 09:26
这个只能隐藏窗口 有没有能隐藏程序的 开机自启,右下角的图标也隐藏的

这个哥们的思想很危险啊哈哈
706349361 发表于 2024-5-6 14:40
感谢楼主分享
Enola 发表于 2024-5-6 15:59
有点意思,看看。
newcools521 发表于 2024-5-6 16:26
狡猾的死啦死啦的
wjayg225 发表于 2024-5-6 18:44
挺好的工具
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则

返回列表

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2025-7-11 02:25

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表