当前位置: 首页 > news >正文

河南建设网站官网chrome官方下载

河南建设网站官网,chrome官方下载,做暑假工的网站,建设银行对账单查询网站写在前面 介绍一个验证过的热键注册工具类,使用系统类库user32.dll中的RegisterHotkey函数来实现全局热键的注册。 代码实现 [Flags]public enum KeyModifiers{Alt 1,Control 2,Shift 4,Windows 8,NoRepeat 0x4000}public static class HotKeyHelper{[DllImp…

写在前面

介绍一个验证过的热键注册工具类,使用系统类库user32.dll中的RegisterHotkey函数来实现全局热键的注册。

代码实现

    [Flags]public enum KeyModifiers{Alt = 1,Control = 2,Shift = 4,Windows = 8,NoRepeat = 0x4000}public static class HotKeyHelper{[DllImport("user32", SetLastError = true)]private static extern bool RegisterHotKey(IntPtr hWnd, int id, uint fsModifiers, uint vk);[DllImport("user32", SetLastError = true)]private static extern bool UnregisterHotKey(IntPtr hWnd, int id);private static int _id = 0;private static volatile MessageWindow _wnd;private static volatile IntPtr _hwnd;private static ManualResetEvent _windowReadyEvent = new ManualResetEvent(false);static HotKeyHelper(){Thread messageLoop = new Thread(delegate (){Application.Run(new MessageWindow());});messageLoop.Name = "MessageLoopThread";messageLoop.IsBackground = true;messageLoop.Start();}public static event EventHandler<HotKeyEventArgs> HotKeyPressed;public static int RegisterHotKey(Keys key, KeyModifiers modifiers){_windowReadyEvent.WaitOne();int id = System.Threading.Interlocked.Increment(ref _id);_wnd.Invoke(new RegisterHotKeyDelegate(RegisterHotKeyInternal), _hwnd, id, (uint)modifiers, (uint)key);return id;}public static void UnregisterHotKey(int id){_wnd.Invoke(new UnRegisterHotKeyDelegate(UnRegisterHotKeyInternal), _hwnd, id);}delegate void RegisterHotKeyDelegate(IntPtr hwnd, int id, uint modifiers, uint key);delegate void UnRegisterHotKeyDelegate(IntPtr hwnd, int id);private static void RegisterHotKeyInternal(IntPtr hwnd, int id, uint modifiers, uint key){RegisterHotKey(hwnd, id, modifiers, key);}private static void UnRegisterHotKeyInternal(IntPtr hwnd, int id){UnregisterHotKey(_hwnd, id);}private static void OnHotKeyPressed(HotKeyEventArgs e){if (HotKeyHelper.HotKeyPressed != null){HotKeyHelper.HotKeyPressed(null, e);}}private class MessageWindow : Form{public MessageWindow(){_wnd = this;_hwnd = this.Handle;_windowReadyEvent.Set();}protected override void WndProc(ref Message m){if (m.Msg == WM_HOTKEY){HotKeyEventArgs e = new HotKeyEventArgs(m.LParam);HotKeyHelper.OnHotKeyPressed(e);}base.WndProc(ref m);}protected override void SetVisibleCore(bool value){// Ensure the window never becomes visiblebase.SetVisibleCore(false);}private const int WM_HOTKEY = 0x312;}}public class HotKeyEventArgs : EventArgs{public readonly Keys Key;public readonly KeyModifiers Modifiers;public HotKeyEventArgs(Keys key, KeyModifiers modifiers){this.Key = key;this.Modifiers = modifiers;}public HotKeyEventArgs(IntPtr hotKeyParam){uint param = (uint)hotKeyParam.ToInt64();Key = (Keys)((param & 0xffff0000) >> 16);Modifiers = (KeyModifiers)(param & 0x0000ffff);}}

调用示例

        void RegisterHotKeyTest(){HotKeyHelper.RegisterHotKey(Keys.B, KeyModifiers.Alt);HotKeyHelper.HotKeyPressed += new EventHandler<HotKeyEventArgs>(OnHotKeyPressed);}void OnHotKeyPressed(object sender, HotKeyEventArgs e){MessageBox.Show("Alt + B");}

执行结果

http://www.15wanjia.com/news/33371.html

相关文章:

  • 外贸网站 建站上海比较大的优化公司
  • 用墨刀做网站后台原型电商网店
  • 在哪修改网站关键词整站seo外包
  • 两学一做 网站企业内训课程
  • 怎么做网站的代理商抓关键词的方法10条
  • 怎样才能在百度上搜到自己的网站简述搜索引擎优化
  • 怎么找做网站客服的工作什么是新媒体营销
  • python 做网站开发吗网络推广要求
  • 网站编辑电子商务网站运营专员湖南seo推广服务
  • 西安网站开发的空间广告营销留电话网站
  • 国外的做的比较优秀的网站百度关键词优化推广
  • wordpress阅读付费网站优化seo推广服务
  • html做高逼格网站快速收录网
  • 家庭宽带做网站服务器广告推广软文案例
  • 家乡网站怎么做广告公司品牌营销推广
  • 微信网站怎么写买卖平台
  • 成都网络优化网站百度口碑网
  • wordpress发布文章报错优化seo培训班
  • 专业外包网站建设公司排名sem推广什么意思
  • 百度网站的优势国际新闻最新消息今天
  • 偷拍做自拍视频网站杯子软文营销300字
  • 做vr效果图的网站关键词优化排名用什么软件比较好
  • 加强公司内部网站建设广东做seo的公司
  • 做网站需要什么步骤seo网络推广是什么意思
  • 专业3合1网站建设公司百度一下子就知道了
  • 网站含中国的备案百度高级搜索怎么用
  • 网站图片移动怎么做的免费引流推广方法
  • 企业做英文网站谷歌google play下载
  • 网站logo多大短视频推广引流方案
  • 宿迁宿城区屠园乡网站建设优化seo是什么