1
1

【FPS向上】Pythonでメインディスプレイ↔拡張モードに切り替えるスクリプト

Posted at

コードを書いたきっかけ

マルチディスプレイを使っているとValorantやApexのFPSが下がったためワンクリックでシングルモニター↔マルチモニターを切り替えれるようにしたかった。

準備するもの

・Python(Path通し済)
・Screeninfoライブラリ

Screeninfoライブラリをインストール

pip install screeninfo

ディスプレイ情報を取得するためのライブラリです。

ソースコード

DisPlaySwitch.py
import subprocess
from screeninfo import get_monitors

# ディスプレイモードを判定する関数
def get_display_mode():
    try:
        monitors = get_monitors()

        # モニターが1つしかない場合は "PC screen only" と判定
        if len(monitors) == 1:
            return "PC screen only"
        else:
            return "Extend"
    except Exception as e:
        print("Error:", str(e))
        return "Error"

def execute_display_mode_script(mode):
    try:
        if mode == "Extend":
            subprocess.run(['DisplaySwitch.exe', '/internal'], shell=True)
        elif mode == "PC screen only":
            subprocess.run(['DisplaySwitch.exe', '/extend'], shell=True)
        else:
            print("Unknown display mode:", mode)
    except Exception as e:
        print("Error:", str(e))

display_mode = get_display_mode()

execute_display_mode_script(display_mode)

仕組み

Screeninfoライブラリからディスプレイ情報を取得して、DisplaySwitchで切り替えてます。

※筆者のPythonバージョンは3.10.2です。

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