Ejemplo n.º 1
0
 private void SendKeyDown(byte keyCode)
 {
     if (!m_PressingKeys.Contains(keyCode))
     {
         NativeCaller.keybd_event(keyCode, 0, 0, (UIntPtr)0);
         m_PressingKeys.Add(keyCode);
     }
 }
Ejemplo n.º 2
0
 private void SendAllKeyUp()
 {
     foreach (byte keyCode in m_PressingKeys)
     {
         NativeCaller.keybd_event(keyCode, 0, 2, (UIntPtr)0);
     }
     m_PressingKeys.Clear();
 }
Ejemplo n.º 3
0
 private void moveMouseByTouchPosition(int x, int y)
 {
     if (m_TargetWindowLeft < 0 || m_TargetWindowTop < 0)
     {
         return;
     }
     NativeCaller.SetCursorPos(m_TargetWindowLeft + x, m_TargetWindowTop + y);
 }
Ejemplo n.º 4
0
 /// <summary>
 /// プロセスの最前面固定設定を解除する
 /// </summary>
 /// <param name="process">対象プロセス</param>
 private void ProcessTopMostRelease(Process process)
 {
     if (null != process)
     {
         NativeCaller.SetWindowPos(process.MainWindowHandle,
                                   (IntPtr)NativeCaller.SpecialWindowHandles.HWND_NOTOPMOST, 0, 0, 0, 0,
                                   NativeCaller.SetWindowPosFlags.SWP_NOMOVE |
                                   NativeCaller.SetWindowPosFlags.SWP_NOSIZE);
     }
 }
Ejemplo n.º 5
0
        private void SendKeyUp(byte keyCode)
        {
            int index = m_PressingKeys.IndexOf(keyCode);

            if (index >= 0)
            {
                NativeCaller.keybd_event(keyCode, 0, 2, (UIntPtr)0);
                m_PressingKeys.RemoveAt(index);
            }
        }
Ejemplo n.º 6
0
 private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
 {
     if (null != m_GettingImageTimer)
     {
         m_GettingImageTimer.Stop();
         m_GettingImageTimer.Dispose();
         m_GettingImageTimer = null;
     }
     if (null != m_TcpClient)
     {
         ReceiveStop();
     }
     SendAllKeyUp();
     if (null != m_TargetProcess)
     {
         NativeCaller.SetWindowPos(m_TargetProcess.MainWindowHandle,
                                   (IntPtr)NativeCaller.SpecialWindowHandles.HWND_NOTOPMOST, 0, 0, 0, 0,
                                   NativeCaller.SetWindowPosFlags.SWP_NOMOVE |
                                   NativeCaller.SetWindowPosFlags.SWP_NOSIZE);
         m_TargetProcess = null;
     }
 }
Ejemplo n.º 7
0
        /// <summary>
        /// 画面取得タイマーを開始する
        /// </summary>
        private void StartGettingImageTimer()
        {
            // 仮で45fps
            m_GettingImageTimer = new System.Timers.Timer(1000 / 45);

            m_GettingImageTimer.Elapsed += (s, e) =>
            {
                try
                {
                    m_GettingImageTimer.Stop();

                    if (null != m_TargetProcess)
                    {
                        IntPtr handle = m_TargetProcess.MainWindowHandle;

                        NativeCaller.POINT screenPoint = new NativeCaller.POINT(0, 0);
                        NativeCaller.ClientToScreen(handle, out screenPoint);

                        NativeCaller.RECT clientRect = new NativeCaller.RECT();
                        NativeCaller.GetClientRect(handle, out clientRect);

                        Rectangle rectangle = new Rectangle(
                            clientRect.Left,
                            clientRect.Top,
                            clientRect.Right - clientRect.Left,
                            clientRect.Bottom - clientRect.Top);

                        Point captureStartPoint = new Point(
                            screenPoint.X + rectangle.X,
                            screenPoint.Y + rectangle.Y);

                        m_TargetWindowLeft   = captureStartPoint.X;
                        m_TargetWindowTop    = captureStartPoint.Y;
                        m_TargetWindowWidth  = rectangle.Width;
                        m_TargetWindowHeight = rectangle.Height;

                        Bitmap   bitmap   = new Bitmap(rectangle.Width, rectangle.Height);
                        Graphics graphics = Graphics.FromImage(bitmap);
                        graphics.CopyFromScreen(captureStartPoint, new Point(0, 0), rectangle.Size);
                        graphics.Dispose();

                        if (null != m_TcpClient && m_TcpClient.Connected)
                        {
                            MemoryStream      memoryStream      = new MemoryStream();
                            EncoderParameters encoderParameters = new EncoderParameters(1);
                            EncoderParameter  parameter         = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, m_ImageQuality);
                            encoderParameters.Param[0] = parameter;
                            bitmap.Save(memoryStream, Util.GetEncoderInfo("image/jpeg"), encoderParameters);
                            byte[] imageBytes = memoryStream.ToArray();
                            memoryStream.Dispose();
                            string ImageBase64String = Convert.ToBase64String(imageBytes);

                            try
                            {
                                NetworkStream networkStream = m_TcpClient.GetStream();
                                byte[]        sendBytes     = Encoding.UTF8.GetBytes(ImageBase64String + "\n");
                                networkStream.BeginWrite(sendBytes, 0, sendBytes.Length, WriteResultCallback, networkStream);
                            }
                            catch (NullReferenceException ex) { }
                            catch (IOException ex) { }
                            catch (ObjectDisposedException ex) { }
                        }

                        if (null != PreviewBox.Image)
                        {
                            PreviewBox.Image.Dispose();
                        }
                        PreviewBox.Image = bitmap;
                    }
                }
                finally
                {
                    if (null != m_GettingImageTimer)
                    {
                        m_GettingImageTimer.Start();
                    }
                }
            };

            m_GettingImageTimer.Start();
        }
Ejemplo n.º 8
0
 /// <summary>
 /// マウスの右ボタンをクリックさせる
 /// </summary>
 public static void MouseRightClick()
 {
     NativeCaller.mouse_event(MouseEventCode.MOUSE_EVENT_RIGHT_DOWN, 0, 0, 0, 0);
     Thread.Sleep(50);
     NativeCaller.mouse_event(MouseEventCode.MOUSE_EVENT_RIGHT_UP, 0, 0, 0, 0);
 }
Ejemplo n.º 9
0
 /// <summary>
 /// マウスの左ボタンをアップさせる
 /// </summary>
 public static void MouseLeftUp()
 {
     NativeCaller.mouse_event(MouseEventCode.MOUSE_EVENT_LEFT_UP, 0, 0, 0, 0);
 }
Ejemplo n.º 10
0
 /// <summary>
 /// マウスの左ボタンをダウンさせる
 /// </summary>
 public static void MouseLeftDown()
 {
     NativeCaller.mouse_event(MouseEventCode.MOUSE_EVENT_LEFT_DOWN, 0, 0, 0, 0);
 }