Example #1
0
        public bool PreFilterMessage(ref Message m)
        {
            switch (m.Msg)                               //判断系统消息的ID号
            {
            //case 0x10E:
            case (int)emWinMsg.eWM_CHAR:
                //截获输入法结果
                IntPtr handle = FindWindow.GetForegroundWindow();
                immStr = getImmStr.CurrentCompStr(handle, m);
                form.SendMessage(immStr);
                MessageBox.Show(immStr);
                break;

            /*case (int)emWinMsg.eWM_IME_CHAR:
             *  //截获输入法结果
             *  handle = FindWindow.GetForegroundWindow();
             *  immStr = getImmStr.CurrentCompStr(handle, m);
             *  //SendMessage(immStr);
             *  MessageBox.Show(immStr);
             *  break;*/
            default:
                //immStr = getImmStr.CurrentCompStr(this.Handle);
                //SendMessage(immStr);
                //base.WndProc(ref m);
                break;
            }
            return(false);
        }
Example #2
0
        protected override void WndProc(ref Message m)
        {
            switch (m.Msg)                               //判断系统消息的ID号
            {
            case (int)emWinMsg.eWM_IME_ENDCOMPOSITION:

                //截获输入法结果
                imeStr = getImeStr.CurrentCompStr(this.Handle);
                if (IsChinese(imeStr))
                {
                    form1.SendMessage(imeStr);
                }
                base.WndProc(ref m);
                break;

            case (int)emWinMsg.eWM_CHAR:
                IntPtr charHandle = FindWindow.GetForegroundWindow();
                imeStr = getImmStr.CurrentCompStr(charHandle, m);
                if (!IsChinese(imeStr))
                {
                    form1.SendMessage(imeStr);
                }
                break;

            default:
                base.WndProc(ref m);
                break;
            }
        }
Example #3
0
        /*private void button5_Click(object sender, EventArgs e)
         * {
         *  _keyboardHook = new KeyboardHookLib();
         *  _keyboardHook.InstallHook(this.OnKeyPress);
         *
         *  //启用客户端输入法的时候,自动让客户端输入法的输入窗口聚焦
         *  FindWindow.SetForegroundWindow(mainHandle);
         *  txtMonitor.Focus();
         * }*/

        /*private void button6_Click(object sender, EventArgs e)
         * {
         *  //解除客户端键盘监控钩子
         *  if (_keyboardHook != null)
         *  {
         *      _keyboardHook.UninstallHook();
         *  }
         *
         *  //启用服务端输入法时,发消息到服务端
         *  SendMessage("使用服务端输入法!");
         * }*/

        /// <summary>
        /// 客户端键盘捕捉事件.
        /// </summary>
        /// <param name="hookStruct">由Hook程序发送的按键信息</param>
        /// <param name="handle">是否拦截</param>
        public void OnKeyPress(KeyboardHookLib.HookStruct hookStruct, out bool handle)
        {
            handle = false; //预设不拦截任何键

            //如果前置窗口时主窗口,则不拦截
            if (FindWindow.GetForegroundWindow() == mainHandle)
            {
                if (tmpCount == 0)
                {
                    tmpCount++;
                    FindWindow.keybd_event((Keys)hookStruct.vkCode, 0, 0, 0);
                    handle = true;
                }
                return;
            }

            //如果键A~Z
            if (hookStruct.vkCode >= (int)Keys.A && hookStruct.vkCode <= (int)Keys.Z &&
                FindWindow.GetForegroundWindow() != mainHandle)
            {
                tmpCount   = 0;
                lastHandle = FindWindow.GetForegroundWindow();
                //A~Z键时,focus隐藏的主窗口
                FindWindow.SetForegroundWindow(mainHandle);
                txtMonitor.Focus();
                tmpCount = 0;

                handle = true;
            }
        }
Example #4
0
        public static string GetFormProcessId()
        {
            int    processId = 0;
            IntPtr handle    = FindWindow.GetActiveWindow();

            processid = GetWindowThreadProcessId(handle, out processId);
            return(processid.ToString());
        }
Example #5
0
 public static void GetFormProcessId()
 {
     while (true)
     {
         int    processId = 0;
         IntPtr handle    = FindWindow.GetForegroundWindow();
         processid = GetWindowThreadProcessId(handle, out processId);
         Thread.Sleep(2000);
     }
 }
Example #6
0
        /* private void txtMonitor_TextChanged(object sender, EventArgs e)
         * {
         *   RemoteApp.MyTextBox.GetComposition getImmStr = new RemoteApp.MyTextBox.GetComposition();
         *   //string immStr;
         *   FindWindow.SetForegroundWindow(lastHandle);
         *   string inputResult = getImmStr.CurrentCompStr(mainHandle,m);
         *   SendMessage(inputResult);
         *   //txtMonitor.Text = "";
         * }*/

        private void Form1_Activated(object sender, EventArgs e)
        {
            //获取主窗口句柄(正式运行时,主窗口是隐藏的)
            mainHandle = FindWindow.GetForegroundWindow();

            button1_Click(this, null);

            //this.Hide();
            //this.Opacity = 0.001;//让客户端窗体的透明度接近看不到
        }
Example #7
0
        private void UseClientInput()
        {
            使用客户端输入法ToolStripMenuItem.Checked = true;
            使用服务端输入法ToolStripMenuItem.Checked = false;

            //_keyboardHook = new KeyboardHookLib();
            _keyboardHook.InstallHook(this.OnKeyPress);

            //启用客户端输入法的时候,自动让客户端输入法的输入窗口聚焦
            FindWindow.SetForegroundWindow(mainHandle);
            txtMonitor.Focus();
        }
Example #8
0
 public void SetLastWindowFocus()
 {
     FindWindow.SetForegroundWindow(lastHandle);
 }