1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

指定のウィンドウをアクティブ・解除するスクリプトをしたい

Last updated at Posted at 2024-03-10

コピペ大好きな自分にとってコピペ先のウィンドウを常に最前面にする必要があったので作成した。

選択したウィンドウが常に最前面かどうか取得してActiveなら解除にしたかったが見つからなかった。

Python
import win32gui
import win32con
import time


def activewindow(wm=0):
    modify = ""
    time.sleep(2)
    #Avtivename
    active_hwnd = win32gui.GetWindowText(win32gui.GetForegroundWindow())
    #ActiveNumber
    hwnd = win32gui.FindWindow(None, active_hwnd)
    #wm = win32gui.GetForegroundWindow() ==  hwnd
    

    if wm == 0:
        win32gui.SetWindowPos(hwnd, win32con.HWND_NOTOPMOST, 0, 0, 0, 0, win32con.SWP_NOMOVE | win32con.SWP_NOSIZE)
        modify = f"ActiveOFF:{active_hwnd}"
    elif wm == 1:
        win32gui.SetWindowPos(hwnd, win32con.HWND_TOPMOST, 0, 0, 0, 0, win32con.SWP_NOMOVE | win32con.SWP_NOSIZE)
        modify = f"ActiveON:{active_hwnd}"
        

    print(modify)
    pykit_tool.send_notification(modify)

    
if __name__=="__main__":
    x = int(input("ActiveON=0\nActiveOFF=1\nActive?:"))

    active_hwnd = activewindow(x)

pykit_tool.send_notificationはwindowsの通知するための機能

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?