Skip to content

Commit b9114ca

Browse files
authored
Merge pull request #19 from IvanHanloth/OptimizeHide
优化窗口隐藏相关功能
2 parents 594dae3 + 503e351 commit b9114ca

File tree

2 files changed

+9
-14
lines changed

2 files changed

+9
-14
lines changed

core/config.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,6 @@ class Config:
3737
"""
3838

3939
hwnd=0
40-
hwnd_b = ""
41-
hwnd_n = ''
4240
times=1
4341

4442
hide_hotkey = "Ctrl+Q"

core/listener.py

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ class HotkeyListener():
1010
def __init__(self):
1111
try:
1212
ShowWindow(Config.hwnd, SW_SHOW)
13-
tool.changeMute(Config.hwnd,0)
13+
if Config.mute_after_hide:
14+
tool.changeMute(Config.hwnd,0)
1415
except:
1516
pass
1617
tool.sendNotify("Boss Key正在运行!", "Boss Key正在为您服务,您可通过托盘图标看到我")
@@ -29,7 +30,6 @@ def reBind(self):
2930
def BindHotKey(self):
3031
self.hotkeys = {
3132
Config.hide_hotkey: self.onHide,
32-
# Config.startup_hotkey: self.onStartup,
3333
Config.close_hotkey: self.Close
3434
}
3535
self.hotkeys = tool.keyConvert(self.hotkeys)
@@ -38,33 +38,30 @@ def BindHotKey(self):
3838
self.listener.start()
3939

4040
def onHide(self,e=""):
41-
Config.hwnd_n = GetForegroundWindow()
4241
if Config.times == 1:
4342
# 隐藏窗口
43+
current = GetForegroundWindow()
4444
if Config.send_before_hide:
4545
time.sleep(0.2)
4646
keyboard.Controller().tap(keyboard.KeyCode.from_vk(0xB2))
4747

48-
ShowWindow(Config.hwnd_n, SW_HIDE)
48+
ShowWindow(current, SW_HIDE)
4949
if Config.mute_after_hide:
50-
tool.changeMute(Config.hwnd_n,1)
51-
Config.hwnd_b=Config.hwnd_n
52-
Config.hwnd=Config.hwnd_b
50+
tool.changeMute(current,1)
51+
Config.hwnd=current
5352
Config.times = 0
5453
else:
5554
# 显示窗口
56-
ShowWindow(Config.hwnd_b, SW_SHOW)
55+
ShowWindow(Config.hwnd, SW_SHOW)
5756
if Config.mute_after_hide:
58-
tool.changeMute(Config.hwnd_b,0)
59-
Config.hwnd_b = ""
57+
tool.changeMute(Config.hwnd,0)
6058
Config.times = 1
6159
Config.save()
6260

6361
def Close(self,e=""):
6462
tool.sendNotify("Boss Key已停止服务", "Boss Key已成功退出")
6563
if Config.times == 0:
66-
ShowWindow(Config.hwnd_b, SW_SHOW)
67-
Config.hwnd_b = ""
64+
ShowWindow(Config.hwnd, SW_SHOW)
6865
Config.times = 1
6966

7067
self.stop()

0 commit comments

Comments
 (0)