Skip to content

Instantly share code, notes, and snippets.

@AndrewPardoe
Last active May 10, 2020 00:57
Show Gist options
  • Save AndrewPardoe/68b298c4396a08834bde to your computer and use it in GitHub Desktop.
Save AndrewPardoe/68b298c4396a08834bde to your computer and use it in GitHub Desktop.
Windows utility to swap mouse button orientation between right-handed mouse and left-handed mouse
/*
Simple utility to swap mouse primary mouse buttons.
Usage: no arguments -> swap buttons
l -> set primary mouse button to right button (e.g., left-hand mouse)
r -> set primary mouse button to left button (e.g., right-hand mouse)
*/
#include "windows.h"
#include <iostream>
using namespace std;
int main(int argc, char* argv[])
{
// GetSystemMetrics(SM_SWAPBUTTON) is nonzero if buttons are swapped
// SwapMouseButton(true) to reverse, (false) to normalize
if (argc > 1)
{
switch (argv[1][0])
{
case 'l':
case 'L':
cout << "Switching primary and secondary buttons." << endl;
SwapMouseButton(true);
break;
case 'r':
case 'R':
cout << "Restoring primary and secondary buttons." << endl;
SwapMouseButton(false);
break;
default:
cout << "Usage: " << argv[0] << " [L|R]" << endl;
break;
}
}
else
{
auto swapped = (GetSystemMetrics(SM_SWAPBUTTON) == 0);
if (swapped)
{
cout << "Primary and secondary buttons were not switched; switching." << endl;
SwapMouseButton(true);
}
else
{
cout << "Primary and secondary buttons were switched; restoring." << endl;
SwapMouseButton(false);
}
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment