Bite Bits/Windows Tips

마우스 좌우 버튼 바꾸기 프로그램 만들기

상영 2016. 6. 2. 10:44

출처 : http://superuser.com/questions/205861/keyboard-shortcut-to-swap-mouse-buttons


마우스 좌우 버튼 바꾸기 설정값은 레지스트리 값에 저장되어 있음.

그리고 cmd 창에서 값 변경이 가능함. 

근데.. 이건 로그인을 새로 해야 효과가 있음.


REG ADD "HKCU\Control Panel\Mouse" /t REG_SZ /v SwapMouseButtons /d 1 /f

or

REG ADD "HKCU\Control Panel\Mouse" /t REG_SZ /v SwapMouseButtons /d 0 /f


However, you need to logout before it will take effect.


더 나은 솔루션으로 c#을 이용해서 작은 .exe 파일을 만들어 사용할 수 있다.

--- (C# 프로그램 소스 : swapmouse.cs) --------------------------------

using System.Runtime.InteropServices;

using System;

using System.Windows.Forms;


class SwapMouse

{

    [DllImport("user32.dll")]

    public static extern Int32 SwapMouseButton(Int32 bSwap);


    static void Main(string[] args)

    {

        int rightButtonIsAlreadyPrimary = SwapMouseButton(1);

        if (rightButtonIsAlreadyPrimary != 0)

        {

            SwapMouseButton(0);  // Make the left mousebutton primary

            MessageBox.Show("오른손용 마우스로 사용");

        }

        else

        {

            MessageBox.Show("왼손용 마우스로 사용");

        }

    }

}

-------------------------------------------------------------------------------


아래의 명령으로 소스 컴파일을 하면 swapmouse.exe 가 만들어진다.

(C# 컴파일을 위해서는 MS .Net framework 가 설치되어 있어야 함)


"%SystemRoot%\Microsoft.NET\Framework64\v3.5\csc" swapmouse.cs


만들어진 exe 파일을 더블클릭하면 마우스 좌우 설정이 즉시 변경됨.