我感觉有一个办法就是建立一个MainMenu,再在上面加一个菜单项,相应功能写入,然后把shortcut设为某一个热键,然后将Mainmenu的visble属性设成False

解决方案 »

  1.   

    应该是说已经存在的窗口吧.也许应在KEYDOWN事件中判断一下热键,然后修改相应窗口的VISIBLE属性吧.
      

  2.   

    每隔一段时间,用GetAsyncKeyState检测是否有指定的键按下。
    我经常这样用,觉得比用钩子简单些。
      

  3.   

    调用API,函数名大概是Setwindowhookex(..)
      

  4.   

    我也想知道,up一下。
    我想能不能在form的keypress里面写呢
      

  5.   

    这段代码对可以在任何时候得到指定的按键时间,你会有用的:
    private void Form1_Load(object sender, System.EventArgs e)
    {
      
    Keys m_hotkey=Keys.Home;
    SetHotKey(m_hotkey, false,false,false,false);
    }
    protected override void WndProc( ref Message m )

    const int WM_HOTKEY = 0x0312;  
                
    switch(m.Msg) 

    case WM_HOTKEY:  
    MessageBox.Show("您点了home键!"); 
    break; 
    }  
    base.WndProc(ref m );
    } public void SetHotKey(Keys c, bool bCtrl, bool bShift, bool bAlt, bool bWindows)
    {
        
    NativeWIN32.KeyModifiers modifiers = NativeWIN32.KeyModifiers.None;
    NativeWIN32.RegisterHotKey(Handle, 100, modifiers, c);
    } public class NativeWIN32
    {
    public NativeWIN32()
    {} [DllImport("user32.dll", CharSet=CharSet.Auto)]
    static public extern IntPtr GetForegroundWindow();  [StructLayout(LayoutKind.Sequential, CharSet=CharSet.Auto)]
    public struct STRINGBUFFER
    {
    [MarshalAs(UnmanagedType.ByValTStr, SizeConst=256)]
    public string szText;
    } [DllImport("user32.dll", CharSet=CharSet.Auto)]
    public static extern int GetWindowText(IntPtr hWnd,  out STRINGBUFFER ClassName, int nMaxCount); [DllImport("user32.dll", CharSet=CharSet.Auto)]
    public static extern int SendMessage(IntPtr hWnd, int msg, int wParam, int lParam); [DllImport("user32.dll", CharSet=CharSet.Auto)]
    public static extern IntPtr SendMessage(IntPtr hWnd, int msg, int wParam, IntPtr lParam); public const int WM_SYSCOMMAND = 0x0112;
    public const int SC_CLOSE = 0xF060; public delegate bool EnumThreadProc(IntPtr hwnd, IntPtr lParam); [DllImport("user32.dll", CharSet=CharSet.Auto)]
    public static extern bool EnumThreadWindows(int threadId, EnumThreadProc pfnEnum, IntPtr lParam); [DllImport("user32.dll", CharSet=CharSet.Auto)]
    public static extern IntPtr FindWindowEx(IntPtr parent, IntPtr next, string sClassName, IntPtr sWindowTitle);
    [DllImport("user32.dll", SetLastError=true)]
    public static extern bool RegisterHotKey( IntPtr hWnd,   
    int id,           
    KeyModifiers fsModifiers,  
    Keys vk           
    ); 
      
    [DllImport("user32.dll", SetLastError=true)]
    public static extern bool UnregisterHotKey( IntPtr hWnd,  
    int id        
    ); [Flags()]
    public enum KeyModifiers
    {  
    None = 0,
    Alt = 1,    
    Control = 2,    
    Shift = 4,    
    Windows = 8
    }
    }
      

  6.   

    看这个例子:http://www.csdn.net/develop/read_article.asp?id=15534
    http://www.csdn.net/develop/read_article.asp?id=15535
      

  7.   

    http://www.vbaccelerator.com/home/NET/Code/Libraries/Windows_Messages/Hot_Key_Form/article.asp