zoukankan      html  css  js  c++  java
  • 响应快捷键,发送指定字符串.(WINDOWS消息,非底层)

     ///注册函数,响应快捷键

            [DllImport("user32.dll")]
            public static extern bool RegisterHotKey(IntPtr wnd, int id, MODKEY mode, Keys vk);
            [DllImport("user32.dll")]
            public static extern bool UnregisterHotKey(IntPtr wnd, int id);
            [Flags()]
            public enum MODKEY { None = 0, ALT = 0x0001, CTRL = 0x0002, SHIFT = 0x0004, WIN = 0x0008, }
            public string mystring = "";
            public Form1()
            {
                InitializeComponent();
                RegisterHotKey(this.Handle, 10, MODKEY.ALT, Keys.R);
                RegisterHotKey(this.Handle, 11, MODKEY.ALT, Keys.Q);
            }

          
            void sendchar(string str)   //发送字符串
            {
                foreach (var s in str)
                { SendKeys.Send(string.Format("{0}", s)); }
            
            
            }
            protected override void WndProc(ref Message m)
            {
                if (m.Msg == 0x0312)
                {
                    switch (m.WParam.ToInt32())
                    {
                        case 10:
                            sendchar(mystring);
                            break;
                        case 11:

                            break;
                        default:
                            break;
                    }
                    return;
                }
                base.WndProc(ref m);
            }

    ///问题:自定义快捷键,底层模拟按键

    //SendKeys.Send // 异步模拟按键(不阻塞UI)

    //SendKeys.SendWait // 同步模拟按键(会阻塞UI直到对方处理完消息后返回)

  • 相关阅读:
    一个图层隶属下一个图层
    windows安装Apache,注册服务出现“(OS 5)拒绝访问。 : AH00369: Failed to open the WinNT service manager..."错误
    windows下apache如何完整卸载?
    重设mysql数据库root用户密码
    mysql设置root密码
    mysql服务无法启动
    ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables opt
    亿丰之星 · 声动亚洲
    Euler's Sum of Powers Conjecture
    MATLAB Hacks from Richard Socher
  • 原文地址:https://www.cnblogs.com/clarklxr/p/9488372.html
Copyright © 2011-2022 走看看