当RDC处于全屏模式时,WH_KEYBOARD_LL无法捕获键盘事件

时间:2013-12-30 00:52:26

标签: c#

我正在做一个c#窗口项目,捕获RDC上每个键盘事件的屏幕截图。   在这个项目中,我使用WH_KEYBOARD_LL钩子来捕捉键盘事件和   微软的RDC。

问题是远程机器的远程会话是否已经存在意味着   有人使用该远程计算机并在未注销的情况下断开连接,WH_KEYBOARD_LL   hook无法在RDC的全屏模式下捕获键盘事件。

因此无法捕获图像。此问题发生在Microsoft server 2008 r2 64 bit上。

我尽可能多地搜索这个。我还是找不到解决办法。

拜托,有人帮我解决这个问题。

编辑:我在代码项目中使用了Gma.Useractivity项目。

     In this project, following is the route given by Gma.Useractivty project to add custom event handler

     public static event KeyEventHandler KeyUp
     {
        add
        {
            EnsureSubscribedToGlobalKeyboardEvents();
            s_KeyUp += value;
        }
        remove
        {
            s_KeyUp -= value;
            TryUnsubscribeFromGlobalKeyboardEvents();
        }
      }


      private static void EnsureSubscribedToGlobalKeyboardEvents()
    {
        // install Keyboard hook only if it is not installed and must be installed
        if (s_KeyboardHookHandle == 0)
        {
            //See comment of this field. To avoid GC to clean it up.
            s_KeyboardDelegate = KeyboardHookProc;
            //install hook
            s_KeyboardHookHandle = SetWindowsHookEx(
                WH_KEYBOARD_LL,
                s_KeyboardDelegate,
                Marshal.GetHINSTANCE(
                    Assembly.GetExecutingAssembly().GetModules()[0]),
                0);
            //If SetWindowsHookEx fails.
            if (s_KeyboardHookHandle == 0)
            {

                //Returns the error code returned by the last unmanaged function called using platform invoke that has the DllImportAttribute.SetLastError flag set. 
                int errorCode = Marshal.GetLastWin32Error();
                //do cleanup


                //Initializes and throws a new instance of the Win32Exception class with the specified error. 
                throw new Exception("@@@ Gma.UserActivityMonitor >> HookeManager.Callbacks.cs [" + "Creating Keyboard Hook is fail] @@@");


            }                     
        }
    }


    I registered my keyboard event handler in the form load as following...

private void RDR9902_Load(object sender,EventArgs e)         {

        rdpProductionNode.FullScreenTitle = "????????(" + CommonData.userID + ")";
        WinAPI.SetWinFullScreen(this.Handle);

        HookManager.KeyDown += new KeyEventHandler(HookManager_KeyDown);
        HookManager.KeyUp += new KeyEventHandler(HookManager_KeyUp);
        HookManager.MouseUp += new MouseEventHandler(HookManager_MouseUp);
    }

0 个答案:

没有答案