#include #include #include #include void print_usage(char* program) { std::cout << "Usage: " << program << " [-s speed acc1 acc2 acc3] [-g]" << std::endl << std::endl << "Options: " << std::endl << " -s speed acc1 acc2 acc3 Sets the speed (1-20) and mouse acceleration" << std::endl << " using specified values." << std::endl << " -g Gets the current speed and mouse acceleration" << std::endl << " information." << std::endl; } int main(int argc, char *argv[]) { bool setMouse = false; bool getMouse = false; int speed, acc1, acc2, acc3; for (int i = 1; i < argc; ++i) { std::string arg(argv[i]); if (arg == "--set" || arg == "-s") { if (i + 4 < argc) { setMouse = true; std::stringstream stream; stream << argv[i + 1] << " " << argv[i + 2] << " " << argv[i + 3] << " " << argv[i + 4]; if (!(stream >> speed && stream >> acc1 && stream >> acc2 && stream >> acc3)) { std::cerr << "Could not convert supplied parameters to integers." << std::endl; print_usage(argv[0]); return 2; } i += 4; } else { std::cerr << "Not enough parameters supplied." << std::endl; print_usage(argv[0]); return 2; } } else if (arg == "--get" || arg == "-g") { getMouse = true; } else { std::cerr << "Unknown parameter " << arg << "." << std::endl; print_usage(argv[0]); return 1; } } if (!getMouse && !setMouse) { print_usage(argv[0]); return 3; } BOOL result; if (getMouse) { int value = 0; result = SystemParametersInfo(SPI_GETMOUSESPEED, NULL, reinterpret_cast(&value), NULL); if (!result) { std::cerr << "Failed to get mouse speed." << std::endl; return 4; } std::cout << "Current mouse speed is " << value << std::endl; int values[3]; result = SystemParametersInfo(SPI_GETMOUSE, NULL, reinterpret_cast(values), NULL); if (!result) { std::cerr << "Failed to get mouse acceleration." << std::endl; return 5; } std::cout << "Current mouse acceleration is " << values[0] << ", " << values[1] << ", " << values[2] << std::endl; std::cout << "Use '" << argv[0] << " -s " << value << " " << values[0] << " " << values[1] << " " << values[2] << "' to set these settings." << std::endl; } if (setMouse) { result = SystemParametersInfo(SPI_SETMOUSESPEED, NULL, reinterpret_cast(speed), SPIF_UPDATEINIFILE | SPIF_SENDWININICHANGE); if (!result) { std::cerr << "Failed to set mouse speed to " << speed << "." << std::endl; return 6; } int values[3]; values[0] = acc1; values[1] = acc2; values[2] = acc3; result = SystemParametersInfo(SPI_SETMOUSE, NULL, reinterpret_cast(values), NULL); if (!result) { std::cerr << "Failed to set mouse acceleration to " << acc1 << ", " << acc2 << ", " << acc3 << "." << std::endl; return 7; } } return 0; }