其实我面对的问题要比这个简单,因为我有一个axWebBrowser控件,然后有一个按纽,单击按纽便打开一个网址,这是非常简单的,现在想实现的就是我按住SHIFT键时能在新窗口打开网页。
关键点在于如何捕获窗体的键盘事件,然后判断是否按下SHIFT键,是的话就新窗口打开,否则就在本窗口打开。
谢谢各位,最后10分~~~

解决方案 »

  1.   

    http://www.syncfusion.com/FAQ/WindowsForms/FAQ_c46c.aspx#q852q
      

  2.   


    If the Control.ModifierKeys doesn't address your issue, then use Platform Invoke and call GetKeyState directly.Declare this class first:  

     
    ComVisibleAttribute(false), 
     
    SuppressUnmanagedCodeSecurityAttribute() 
     

     
    internal class NativeMethods 
     

     
         [DllImport("user32.dll", CharSet=CharSet.Auto, ExactSpelling=true, CallingConvention=CallingConvention.Winapi)] 
     
         public static extern short GetKeyState(int keyCode); 
      
         public static int HIWORD(int n) 
     
         { 
     
              return ((n >> 16) & 0xffff/*=~0x0000*/); 
     
         } 
      
         public static int LOWORD(int n) 
     
         { 
     
              return (n & 0xffff/*=~0x0000*/); 
     
         } 
     

      
    Then when you want to check if Caps is down or ON, call:  
    short state = NativeMethods.GetKeyState(0x14 /*VK_CAPTIAL*/); 
      
    bool capsKeyDown = NativeMethods.HIWORD(state); 
     
    bool capsKeyON = NativeMethods.LOWORD(state);