C #: the habit of switching the left and right hands of the mouse

Source: Internet
Author: User

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  
  1. Using system;
  2. Using system. runtime. interopservices;
  3. Using Microsoft. Win32;
  4. Namespace swapmousemodel
  5. {
  6. Class Program
  7. {
  8. [Dllimport ("USER32")]
  9. Public static extern int swapmousebutton (INT bswap );
  10. [Dllimport ("USER32")]
  11. Public static extern int getsystemmetrics (INT nindex );
  12. // Public readonly static int sm_swapbutton = 23;
  13. Public const int sm_swapbutton = 23;
  14. Public static void main (string [] ARGs)
  15. {
  16. Var key = registry. currentuser. createsubkey ("Control Panel \ mouse \\");
  17. If (getsystemmetrics (sm_swapbutton) = 0)
  18. {
  19. // Case: Right Hand model, change to left hand model.
  20. Swapmousebutton (1 );
  21. Key. setvalue ("swapmousebuttons", "1", registryvaluekind. String );
  22. }
  23. Else
  24. {
  25. // Case: Left Hand model, change to right hand model.
  26. Swapmousebutton (0 );
  27. Key. setvalue ("swapmousebuttons", 0, registryvaluekind. String );
  28. }
  29. Console. writeline ("end ");
  30. // Console. Readline ();
  31. }
  32. }
  33. }

 

 

 

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.