国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學(xué)院 > 開發(fā)設(shè)計 > 正文

使用C#:自動切換鼠標的左右手習(xí)慣

2019-11-14 16:35:00
字體:
供稿:網(wǎng)友

不知道我得的是鼠標手,還是肩周炎。

長時間右手(或者左手)使用鼠標的話,那只胳膊便會不自在。

于是便有了切換鼠標主次要鍵的需求。

 

【控制面板->鼠標】有更改它的設(shè)置,可點來點去讓我覺得不夠方便。

我需要的是“一個命令就能搞定它”,這樣我就可以在命令行,或者程序加載器里面方便的運行他。

 

下面的代碼便是要實現(xiàn)這一需求:

他是一個命令行程序。如果當前鼠標是右手習(xí)慣,則將鼠標習(xí)慣設(shè)置為左手,反之設(shè)置成右手習(xí)慣。

 

實現(xiàn)代碼如下:

 

C#代碼  收藏代碼
  1. using System;  
  2. using System.Runtime.InteropServices;  
  3. using Microsoft.Win32;  
  4.   
  5. namespace SwapMouseModel  
  6. {  
  7.     class PRogram  
  8.     {  
  9.         [DllImport("user32")]  
  10.         public static extern int SwapMouseButton(int bSwap);  
  11.   
  12.         [DllImport("user32")]  
  13.         public static extern int GetSystemMetrics(int nIndex);  
  14.   
  15.         //public readonly static int SM_SWAPBUTTON = 23;  
  16.         public const int SM_SWAPBUTTON = 23;  
  17.   
  18.         public static void Main(string[] args)  
  19.         {  
  20.   
  21.             var key = Registry.CurrentUser.CreateSubKey("Control Panel//Mouse//");  
  22.               
  23.   
  24.             if (GetSystemMetrics(SM_SWAPBUTTON) == 0)  
  25.             {  
  26.                 //case: right hand model, change to left hand model.  
  27.                 SwapMouseButton(1);  
  28.                 key.SetValue("SwapMouseButtons", "1", RegistryValueKind.String);  
  29.             }  
  30.             else  
  31.             {  
  32.                 //case: left hand model, change to right hand model.  
  33.                 SwapMouseButton(0);  
  34.                 key.SetValue("SwapMouseButtons", 0, RegistryValueKind.String);  
  35.             }  
  36.             Console.WriteLine("end");  
  37.             //Console.ReadLine();  
  38.         }  
  39.     }  
  40. }  

 

 

 

總結(jié)下對C#新認識:

 

1. static與const不能同時修飾一個變量

    類成員是const就自動是static。因此或者只用const, 或者可以用readonly static

2. SwapMouseButton Function

    通過該鏈接可以展開查看“windows關(guān)于mouse”的api。

    另外注意,該方法不會修改注冊表。所以為了重啟后修改依然有效,需要另行保存注冊表設(shè)置。

3. GetSystemMetrics Function

    通過該鏈接可以展開查看如何獲得“其他類似的屬性”

4. C#中可以使用var。

 

Google到的參考鏈接:

http://www.theeldergeek.com/forum/lofiversion/index.php?t10400.html

http://stackoverflow.com/questions/653911/swapping-left-and-right-mouse-button-in-net


發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 三台县| 德安县| 云梦县| 拜城县| 本溪市| 左权县| 龙川县| 泸定县| 油尖旺区| 北川| 体育| 唐海县| 二连浩特市| 沧源| 陆良县| 延庆县| 蒙山县| 探索| 大余县| 通城县| 双峰县| 佛山市| 临夏县| 阿拉尔市| 双辽市| 莱阳市| 通城县| 连山| 大庆市| 奇台县| 岢岚县| 洪江市| 商城县| 巨鹿县| 弥渡县| 宁津县| 隆化县| 合江县| 临海市| 宁津县| 尼木县|