I don't know if I have a mouse or a shoulder.
The right hand (or left hand) uses the mouse for a long time, and the arm is uncomfortable.
Therefore, you need to switch the Primary and Secondary mouse keys.
[Control Panel-> Mouse] You can click it to make it inconvenient.
What I need is "a command can handle it", so that I can conveniently run it in the command line or program loader.
The following code implements this requirement:
It is a command line program. If the current mouse is the right hand habit, set the mouse habit to the left hand, and vice versa.
The implementation code is as follows:
C # code
- Using system;
- Using system. runtime. interopservices;
- Using Microsoft. Win32;
- Namespace swapmousemodel
- {
- Class Program
- {
- [Dllimport ("USER32")]
- Public static extern int swapmousebutton (INT bswap );
- [Dllimport ("USER32")]
- Public static extern int getsystemmetrics (INT nindex );
- // Public readonly static int sm_swapbutton = 23;
- Public const int sm_swapbutton = 23;
- Public static void main (string [] ARGs)
- {
- Var key = registry. currentuser. createsubkey ("Control Panel \ mouse \\");
- If (getsystemmetrics (sm_swapbutton) = 0)
- {
- // Case: Right Hand model, change to left hand model.
- Swapmousebutton (1 );
- Key. setvalue ("swapmousebuttons", "1", registryvaluekind. String );
- }
- Else
- {
- // Case: Left Hand model, change to right hand model.
- Swapmousebutton (0 );
- Key. setvalue ("swapmousebuttons", 0, registryvaluekind. String );
- }
- Console. writeline ("end ");
- // Console. Readline ();
- }
- }
- }
Summary of C #'s new understanding:
1. Static and const cannot modify a variable at the same time.
If the class member is const, it is automatically static. Therefore, you can only use const, or use readonly static
2. swapmousebutton Function
You can click this link to view the "Windows mouse" API.
Note that this method does not modify the registry. Therefore, you need to save the Registry Settings separately to make the changes remain valid after restart.
3. getsystemmetrics Function
You can use this link to view how to obtain "other similar properties"
4. var can be used in C.
Google reference link:
Http://www.theeldergeek.com/forum/lofiversion/index.php? T10400.html
Http://stackoverflow.com/questions/653911/swapping-left-and-right-mouse-button-in-net