实现快捷键Alt+F12显示/隐藏程序功能

想实现注册类似于ctr+alt+shit+A+Z的方法很简单,将RegisterHotKey的第3个参数设置为KeyModifiers.Alt|KeyModifiers.Control|KeyModifiers.Shift,
第4个参数设置为Keys.B|Keys.Z。
 
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Threading;
namespace rgHotKeys
{
    public enum KeyModifiers
    {
        None = 0,
        Alt = 1,
        Control = 2,
        Shift = 4,
        Windows = 8
    }
    public partial class Form1 : Form
    {
        [DllImport("user32.dll",SetLastError=true)]
        public static extern bool  RegisterHotKey(IntPtr hwnd,int id,int fsModifiers,int vk);
        [DllImport("user32.dll", SetLastError = true)]
        public static extern bool UnregisterHotKey(
         IntPtr hWnd, // handle to window
         int id // hot key identifier
        );
        private int id;
        public Form1()
        {
            InitializeComponent();
        }
        private void Form1_Load(object sender, EventArgs e)
        {
            id = Thread.CurrentThread.GetHashCode();
            RegisterHotKey(this.Handle, id, (int)KeyModifiers.Alt, (int)Keys.F12);
        }
        protected override void WndProc(ref Message m)
        {
            const int WM_HOTKEY = 0x0312;
            switch (m.Msg)
            {
                case WM_HOTKEY:
                  if(id==(int)m.WParam)
                  {
                            System.Windows.Forms.MessageBox.Show ("你好!");
                    }
               break;
            }
            base.WndProc(ref m);
        }
        private void Form1_FormClosed(object sender, FormClosedEventArgs e)
        {
            UnregisterHotKey(this.Handle, 10001);
        }
    }
}

 

 

二、

想实现注册类似于ctr+alt+shit+A+Z的方法很简单,将RegisterHotKey的第3个参数设置为KeyModifiers.Alt|KeyModifiers.Control|KeyModifiers.Shift,
第4个参数设置为Keys.B|Keys.Z。
 
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Threading;
namespace rgHotKeys
{
    public enum KeyModifiers
    {
        None = 0,
        Alt = 1,
        Control = 2,
        Shift = 4,
        Windows = 8
    }
    public partial class Form1 : Form
    {
        [DllImport("user32.dll",SetLastError=true)]
        public static extern bool  RegisterHotKey(IntPtr hwnd,int id,int fsModifiers,int vk);
        [DllImport("user32.dll", SetLastError = true)]
        public static extern bool UnregisterHotKey(
         IntPtr hWnd, // handle to window
         int id // hot key identifier
        );
        private int id;
        public Form1()
        {
            InitializeComponent();
        }
        private void Form1_Load(object sender, EventArgs e)
        {
            id = Thread.CurrentThread.GetHashCode();
            RegisterHotKey(this.Handle, id, (int)KeyModifiers.Alt, (int)Keys.F12);
        }
        protected override void WndProc(ref Message m)
        {
            const int WM_HOTKEY = 0x0312;
            switch (m.Msg)
            {
                case WM_HOTKEY:
                  if(id==(int)m.WParam)
                  {
                            System.Windows.Forms.MessageBox.Show ("你好!");
                    }
               break;
            }
            base.WndProc(ref m);
        }
        private void Form1_FormClosed(object sender, FormClosedEventArgs e)
        {
            UnregisterHotKey(this.Handle, 10001);
        }
    }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Ctrl+N 查找类 Ctrl+Shift+N 查找文件 Ctrl+Alt+L 格式化代码 Ctrl+Alt+O 优化导入的类和包 Alt+Insert 生成代码(如get,set方法,构造函数等) Ctrl+E或者Alt+Shift+C 最近更改的代码 Ctrl+R 替换文本 Ctrl+F 查找文本 Ctrl+Shift+Space 自动补全代码 Ctrl+空格 代码提示 Ctrl+Alt+Space 类名或接口名提示 Ctrl+P 方法参数提示 Ctrl+Shift+Alt+N 查找类中的方法或变量 Alt+Shift+C 对比最近修改的代码 Shift+F6 重构-重命名 Ctrl+Shift+先上键 Ctrl+X 删除行 Ctrl+D 复制行 Ctrl+/ 或 Ctrl+Shift+/ 注释(// 或者/*...*/ ) Ctrl+J 自动代码 Ctrl+E 最近打开的文件 Ctrl+H 显示类结构图 Ctrl+Q 显示注释文档 Alt+F1 查找代码所在位置 Alt+1 快速打开或隐藏工程面板 Ctrl+Alt+ left/right 返回至上次浏览的位置 Alt+ left/right 切换代码视图 Alt+ Up/Down 在方法间快速移动定位 Ctrl+Shift+Up/Down 代码向上/下移动。 F2 或Shift+F2 高亮错误或警告快速定位 代码标签输入完成后,按Tab,生成代码。 选中文本,按Ctrl+Shift+F7 ,高亮显示所有该文本,按Esc高亮消失。 Ctrl+W 选中代码,连续按会有其他效果 选中文本,按Alt+F3 ,逐个往下查找相同文本,并高亮显示。 Ctrl+Up/Down 光标跳转到第一行或最后一行下 Ctrl+B 快速打开光标处的类或方法 Intellij IDEA最常用快捷键 1.Ctrl+E,可以显示最近编辑的文件列表 2.Shift+Click可以关闭文件 3.Ctrl+[或]可以跳到大括号的开头结尾 4.Ctrl+Shift+Backspace可以跳转到上次编辑的地方 5.Ctrl+F12,可以显示当前文件的结构 6.Ctrl+F7可以查询当前元素在当前文件中的引用,然后按F3可以选择 7.Ctrl+N,可以快速打开类 8.Ctrl+Shift+N,可以快速打开文件 9.Alt+Q可以看到当前方法的声明 10.Ctrl+W可以选择单词继而语句继而行继而函数 11.Alt+F1可以将正在编辑的元素在各个面板中定位 12.Ctrl+P,可以显示参数信息 13.Ctrl+Shift+Insert可以选择剪贴板内容并插入 14.Alt+Insert可以生成构造器/Getter/Setter等 15.Ctrl+Alt+V 可以引入变量。例如把括号内的SQL赋成一个变量 16.Ctrl+Alt+T可以把代码包在一块内,例如try/catch 17.Alt+Up and Alt+Down可在方法间快速移动

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值