LoginSignup
0
0

More than 1 year has passed since last update.

マウススクロールを逆にするだけのスクリプト

Posted at

はじめに

Windows と Mac をどちらも使っているとマウスのスクロール方向で混乱することがあります。
私は Mac を使っている時間のほうが長いので Windows の方のスクロールを逆にすることで対処しています。
このスクロールを逆にするというのが少し面倒で、レジストリを書き換える必要があります。
これを簡略化するためのスクリプトです。

ソースコード

MouseReverse.py
import winreg

root: str = "SYSTEM\\CurrentControlSet\\Enum\\HID"

def open_rec(key_str: str, depth: int):
    with winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, key_str, 0, winreg.KEY_READ | winreg.KEY_WRITE) as key:
        [sub_key_num, val_num, modified] = winreg.QueryInfoKey(key)
        # 値を列挙する
        updated: bool = False
        for i in range(0, val_num):
            [name, val, type] = winreg.EnumValue(key, i)
            # マウスのスクロール方向を表すキーだけ拾う
            if name == 'FlipFlopWheel' or name == 'FlipFlopHScroll':
                print(f'{key_str}\\{name}({val})')
                try:
                    winreg.SetValueEx(key, name, 0, winreg.REG_DWORD, 1)
                except:
                    import traceback
                    traceback.print_exc()
                updated = True
        if updated:
            winreg.FlushKey(key_str)
        # サブキーを開く
        for i in range(0, sub_key_num):
            sub_key = winreg.EnumKey(key, i)
            try:
                open_rec(f'{key_str}\\{sub_key}', depth + 1)
            except:
                pass

open_rec(root, 0)

注意点

管理者権限のコマンドプロンプトでないと実行できません。

0
0
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
0
0