Пример #1
0
        public void MovePiece(int screen, string szMove)
        {
            int start_x, start_y, end_x, end_y;


            int sx, sy, ex, ey;

            start_x = szMove[0] - 'a';
            start_y = szMove[1] - '1';
            end_x   = szMove[2] - 'a';
            end_y   = szMove[3] - '1';


            int s_screenX, s_screenY;
            int e_screenX, e_screenY;

            if (chessboardCoord != null)
            {
                s_screenX = chessboardCoord.Left + (chessboardCoord.Width / 16) + (chessboardCoord.Width * start_x) / 8;
                s_screenY = chessboardCoord.Bottom - (chessboardCoord.Height / 16) - (chessboardCoord.Height * start_y) / 8;

                e_screenX = chessboardCoord.Left + (chessboardCoord.Width / 16) + (chessboardCoord.Width * end_x) / 8;
                e_screenY = chessboardCoord.Bottom - (chessboardCoord.Height / 16) - (chessboardCoord.Height * end_y) / 8;

                System.Windows.Forms.Screen[] scrn = System.Windows.Forms.Screen.AllScreens;

                s_screenX += scrn[screen].Bounds.X;
                s_screenY += scrn[screen].Bounds.Y;

                e_screenX += scrn[screen].Bounds.X;
                e_screenY += scrn[screen].Bounds.Y;


                MouseOperations.SetCursorPosition(s_screenX, s_screenY);
                System.Threading.Thread.Sleep(200);
                MouseOperations.MouseEvent(MouseOperations.MouseEventFlags.LeftDown);
                System.Threading.Thread.Sleep(200);

                for (int ii = 0; ii < 10; ii++)
                {
                    int x = ((ii * e_screenX) + ((10 - ii) * s_screenX)) / 10;
                    int y = ((ii * e_screenY) + ((10 - ii) * s_screenY)) / 10;

                    MouseOperations.SetCursorPosition(x, y);
                    System.Threading.Thread.Sleep(20);
                }

                MouseOperations.SetCursorPosition(e_screenX, e_screenY);
                System.Threading.Thread.Sleep(200);
                MouseOperations.MouseEvent(MouseOperations.MouseEventFlags.LeftUp);

                if (szMove.Length > 4)
                {
                    int p_screenX = 0, p_screenY = 0;
                    p_screenX = e_screenX;
                    // promotion!!!!!
                    if (szMove[4] == 'q')
                    {
                        p_screenY = e_screenY;
                    }
                    if (szMove[4] == 'k')
                    {
                        if (end_y == 8)
                        {
                            p_screenY = e_screenY + (chessboardCoord.Width * 1) / 8;
                        }
                        else
                        {
                            p_screenY = e_screenY - (chessboardCoord.Width * 1) / 8;
                        }
                    }
                    p_screenY = e_screenY + (chessboardCoord.Width * 1) / 8;
                    if (szMove[4] == 'r')
                    {
                        if (end_y == 8)
                        {
                            p_screenY = e_screenY + (chessboardCoord.Width * 2) / 8;
                        }
                        else
                        {
                            p_screenY = e_screenY - (chessboardCoord.Width * 2) / 8;
                        }
                    }
                    if (szMove[4] == 'b')
                    {
                        if (end_y == 8)
                        {
                            p_screenY = e_screenY + (chessboardCoord.Width * 3) / 8;
                        }
                        else
                        {
                            p_screenY = e_screenY - (chessboardCoord.Width * 3) / 8;
                        }
                    }
                    System.Threading.Thread.Sleep(400);
                    MouseOperations.SetCursorPosition(p_screenX, p_screenY);
                    System.Threading.Thread.Sleep(100);
                    MouseOperations.MouseEvent(MouseOperations.MouseEventFlags.LeftDown);
                    System.Threading.Thread.Sleep(100);
                    MouseOperations.MouseEvent(MouseOperations.MouseEventFlags.LeftUp);
                }
            }
            else
            {
                //error
            }
        }
Пример #2
0
 private void timer1_Tick(object sender, EventArgs e)
 {
     MouseOperations.MousePoint pos = MouseOperations.GetCursorPosition();
     textBoxMoussePos.Text = "X:" + System.Windows.Forms.Control.MousePosition.X + " Y:" + System.Windows.Forms.Control.MousePosition.Y;
 }