keyhac
keyhac copied to clipboard
setForeground で Firefoxがフォアグラウンド化できない
Blogで下記で動くとのコメントあり。
def check_run(path, class_name=""): wnd = find_window(class_name) if wnd: if wnd.isMinimized(): wnd.restore() wnd.getLastActivePopup().setForeground() else: keymap.ShellExecuteCommand(None, path, "", "").executeFunc()
def find_window(class_name): def get_window(wnd, arg): nonlocal window if wnd.isVisible() and not wnd.getOwner(): if wnd.getClassName() == class_name: window = wnd return False return True
window = None Window.enum(get_window, None) return window
keymap_global["A-C"] = lambda: check_run(r"C:/Program Files/Mozilla Firefox/firefox.exe", "MozillaWindowClass")
上のコードで動作しました。 インデント付きを置いておきます。
def find_window(class_name):
def get_window(wnd, arg):
nonlocal window
if wnd.isVisible() and not wnd.getOwner():
if wnd.getClassName() == class_name:
window = wnd
return False
return True
window = None
Window.enum(get_window, None)
return window
def check_run(path="", class_name=""):
wnd = find_window(class_name)
if wnd:
if wnd.isMinimized():
wnd.restore()
wnd.getLastActivePopup().setForeground()
else:
executeFunc = keymap.ShellExecuteCommand(None, path, "", "")
executeFunc()