日期:2014-05-17  浏览次数:20999 次

C#中窗体屏蔽键盘按键

重写Wndproc示例:

static bool flag = false;
        protected override void WndProc(ref Message m)
        {
           switch (m.Msg) {
                 case 0x0200: //WM_MOUSEMOVE
                         if (flag)
                         {
                             PostMessage(this.Handle, 0x00A1,new IntPtr(2),m.LParam);//这里需要导入 user32.dll 
                         }
                         break;
                     case 0x201://WM_LBUTTONDOWN
                         flag = true;
                         break;
                     case 0x202://WM_LBUTTONUP
                        flag = false;

                               break;

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

      [DllImport("user32.dll", CharSet = CharSet.Unicode)]
        public static extern IntPtr PostMessage(IntPtr hwnd, int wMsg, IntPtr wParam, IntPtr lParam);





虚拟键盘代码                        16进制值                          对应键   
VK_LBUTTON      &