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

首頁 > 開發 > 綜合 > 正文

C#中定義熱鍵

2024-07-21 02:26:40
字體:
來源:轉載
供稿:網友
  • 網站運營seo文章大全
  • 提供全面的站長運營經驗及seo技術!
  •  以一個form程序為例

    public class form1 : form

    {
                private void form1_load(object sender, system.eventargs e)
                {
                            sethotkey(false, false, false, true, keys.right, 100); // 設置多個熱鍵
                            sethotkey(false, false, false, true, keys.space, 101);
                            sethotkey(false, false, false, true, keys.up, 102);
                            sethotkey(false, false, false, true, keys.down, 103);
                }
                
                private bool key_ctrl = false;
                private bool key_shift = false;
                private bool key_alt = false;
                private bool key_windows = false;
                private keys   key_other;

                public void sethotkey(bool bctrl,bool bshift,bool balt,bool  bwindows,keys nowkey,int keyid)
                {
                      try
                      {
                            this.key_alt = balt;
                            this.key_ctrl = bctrl;
                            this.key_shift = bshift;
                            this.key_windows = bwindows;
                            this.key_other = nowkey;
               
                            winhotkey.keymodifiers modifier = winhotkey.keymodifiers.none;
               
                            if( this.key_ctrl )
                                  modifier |= winhotkey.keymodifiers.control;
                            if(this.key_alt )
                                  modifier |= winhotkey.keymodifiers.alt;
                            if(this.key_shift)
                                  modifier |= winhotkey.keymodifiers.shift;
                            if(this.key_windows)
                                  modifier |= winhotkey.keymodifiers.windows;
               
                            winhotkey.registerhotkey(handle,keyid,modifier,nowkey);
                      }
                      catch
                      {
                            messagebox.show ("快捷鍵定義錯誤!");
                      }
                }
               
                protected override void wndproc(ref message msg )
                {
                      const int wm_hotkey =  0x0312; // 熱鍵消息

                      if (msg.msg != wm_hotkey)
                      {
                            base.wndproc(ref msg);
                      }
                      else
                      {
                                      //激活熱鍵,在此可以添加處理程序
                                      if (100 == (int)msg.wparam)
                                      {
                                                  //dosomething
                                      }
                                      else if (101 == (int)msg.wparam)
                                      {
                                                  //dosomething
                                      }
                                      else if (102 == (int)msg.wparam)
                                      {
                                                  //dosomething
                                      }
                                      else
                                      {
                                                  //dosomething
                                      }
                      }
               }

                private void form1_closing(object sender, system.componentmodel.canceleventargs e)
                {
                    winhotkey.unregisterhotkey(handle, 100);      // 注銷熱鍵
                    winhotkey.unregisterhotkey(handle, 101);      // 注銷熱鍵
                    winhotkey.unregisterhotkey(handle, 102);      // 注銷熱鍵
                    winhotkey.unregisterhotkey(handle, 103);      // 注銷熱鍵
                }

     

    public class winhotkey
    {
                public winhotkey()
                {
               
                }

                [dllimport("user32.dll",setlasterror=true)]
                public static extern bool registerhotkey(
                      intptr hwnd,
                      int id,
                      keymodifiers fsmodifiers,
                      keys vk
                      );

                [dllimport("user32.dll",setlasterror=true)]
                public static extern bool unregisterhotkey(
                      intptr hwnd,
                      int id
                      );

                [flags()]
                public enum keymodifiers
                {
                      none = 0,
                      alt = 1,
                      control =2,
                      shift = 4,
                      windows = 8
                }

    }

    這樣就完成了熱鍵的定義


    發表評論 共有條評論
    用戶名: 密碼:
    驗證碼: 匿名發表
    主站蜘蛛池模板: 磴口县| 肃宁县| 临沂市| 靖宇县| 潮安县| 建昌县| 柞水县| 加查县| 左云县| 汽车| 大同县| 张北县| 西丰县| 长泰县| 柘荣县| 同仁县| 壤塘县| 金坛市| 成安县| 斗六市| 凭祥市| 周口市| 温宿县| 长子县| 岳西县| 西昌市| 威宁| 舒兰市| 高要市| 太保市| 毕节市| 柯坪县| 织金县| 乐昌市| 博白县| 常山县| 芒康县| 玉田县| 屏东市| 融水| 绥滨县|