-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPowerToysRunEnhance.py
33 lines (27 loc) · 1.02 KB
/
PowerToysRunEnhance.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import uiautomation as automation
import comtypes
import os
import string
from pynput import keyboard
import pyautogui
alphabet = list(string.ascii_lowercase)
def on_press(key):
try:
if key.char.lower() in alphabet:
comtypes.CoInitialize()
window = automation.WindowControl(Name="搜索", className="Windows.UI.Core.CoreWindow", searchDepth=2)
if window.Exists(0, 0):
RichEditBox = window.EditControl(AutomationId="SearchTextBox", className="RichEditBox")
ValuePattern = RichEditBox.GetPattern(automation.PatternId.ValuePattern)
if ValuePattern is None:
value = ''
else:
value = ValuePattern.Value
os.kill(window.ProcessId, 9)
pyautogui.hotkey("alt", "space")
pyautogui.typewrite(value)
comtypes.CoUninitialize()
except AttributeError:
pass
with keyboard.Listener(on_press=on_press) as listener:
listener.join()