回転:C#マウスクリック、移動、プーリスクロール

5214 ワード

C#コントロールマウスクリック、移動、滑車スクロール2018年04月15日23:41:57読書数:40先日何気なく携帯電話のソフトを発見しました.ニュースをクリックして、入ってから、しばらくして画面をスライドして、20秒以上で金貨を手に入れることができます.その時、自分でプログラムを書いて、マウスのクリック、移動、プーリのスクロールをシミュレートして、携帯電話をパソコンに接続して、パソコンで携帯電話の画面をコントロールする方法があるかどうか考えていました(私はC#で、このように変換するしかありません.Androidなら直接コントロールハンドマシンを書きます).インターネットでいくつかの方法を調べて、自分で書いたものと結びつけました.次はマウスクリック、移動、プーリスクロールの方法です.[csharp] view plain copy [DllImport(“user32.dll”)] static extern void mouse_event(int flags, int dX, int dY, int buttons, int extraInfo);
   const int MOUSEEVENTF_MOVE = 0x1;//        
   const int MOUSEEVENTF_LEFTDOWN = 0x2;//  
   const int MOUSEEVENTF_LEFTUP = 0x4;  
   const int MOUSEEVENTF_RIGHTDOWN = 0x8;  
   const int MOUSEEVENTF_RIGHTUP = 0x10;  
   const int MOUSEEVENTF_MIDDLEDOWN = 0x20;  
   const int MOUSEEVENTF_MIDDLEUP = 0x40;  
   const int MOUSEEVENTF_WHEEL = 0x800;  
   const int MOUSEEVENTF_ABSOLUTE = 0x8000;  

[csharp]view plain copy//マウスを座標((int_X+100)*65536/1366、(int_Y+move_long)*65536/768)という絶対位置に移動させるように制御します.1366と768はコンピュータのスクリーンの解像度で、私のコンピュータは1366*768の解像度/解像度は自分のコンピュータによって正しく設定して、さもなくば獲得した座標は正確ではありません.mouse_event(MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_MOVE, (int_X + 100) * 65536/1366, (int_Y + move_long) * 65536/768, 0, 0); [csharp] view plain copy
[csharp]view plain copy//マウスをその場で左クリック(点下と離す)mouse_event(MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP, 0, 0, 0, 0); [csharp]view plain copy//マウスホイールのスクロールを制御し、countはスクロールの値を表し、負数は下を表し、正数は上を表し、例えば-100は下をスクロール100のy座標mouse_を表すevent(MOUSEEVENTF_WHEEL, 0, 0, count, 0);
次は私が書いたこのソフトの
すべてのコード:[csharp]view plain copy
[csharp] view plain copy public Form1() { InitializeComponent(); } private static int count = -100;//マウスの上下スクロール距離private int state=1;//マウスが上にスクロールするか下にスクロールするかを記録private int_X;//マウスクリック座標のX private int_Y;//マウスクリック座標のY private int time=0;//実行時間を記録private int move_long = 0; private int settime = 0; private int clickCount = 5; private void Form1_Load(object sender,EventArgs e){//100ミリ秒ごとにマウス座標を取得し、マウスのクリック場所の座標timer 2.Enabled=trueを取得する;timer 2.Interval=100;
    }  

    [DllImport("user32.dll")]  
    static extern void mouse_event(int flags, int dX, int dY, int buttons, int extraInfo);  

    const int MOUSEEVENTF_MOVE = 0x1;//        
    const int MOUSEEVENTF_LEFTDOWN = 0x2;//  
    const int MOUSEEVENTF_LEFTUP = 0x4;  
    const int MOUSEEVENTF_RIGHTDOWN = 0x8;  
    const int MOUSEEVENTF_RIGHTUP = 0x10;  
    const int MOUSEEVENTF_MIDDLEDOWN = 0x20;  
    const int MOUSEEVENTF_MIDDLEUP = 0x40;  
    const int MOUSEEVENTF_WHEEL = 0x800;  
    const int MOUSEEVENTF_ABSOLUTE = 0x8000;  




    //          
    private void timer1_Tick(object sender, EventArgs e)  
    {  
        time++;//        
        clickCount++;  
        txt_content.Text = clickCount.ToString();  
        if (clickCount < 4)  
        {  
            //         ((int_X + 100) * 65536 / 1366, (int_Y + move_long) * 65536 / 768)       。1366 768         ,     1366*768      
            //               ,           。  
            mouse_event(MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_MOVE, (int_X + 100) * 65536 / 1366, (int_Y + move_long) * 65536 / 768, 0, 0);  
        }  
        if (clickCount == 4)  
        {  
            //           (     )  
            mouse_event(MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);  
            time = 1;  
            txt_content.Text = clickCount.ToString()+":    ";  
            return;  
        }  
        if (time % (settime / 3) == 0)  
        {  


            mouse_event(MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_MOVE, int_X * 65536 / 1366, (int_Y) * 65536 / 768, 0, 0);  
            mouse_event(MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);  
            clickCount = 0;  
            time = 1;  

        }  
        else  
        {  
            if (state == 1)  
            {  
                count = 100;//  
            }  
            else  
            {  
                count = -100;//          
            }  
            //        ,count      ,      ,      , -100      100 y    
            mouse_event(MOUSEEVENTF_WHEEL, 0, 0, count, 0);  
            if (state == 1)  
            {  
                state = 0;  
            }  
            else  
            {  
                state = 1;  
            }  

        }  

    }  

    private void btn_start_Click(object sender, EventArgs e)  
    {  
        timer2.Enabled = false;  
        timer1.Enabled = true;  
        move_long = int.Parse(txt_long.Text);  
        settime = int.Parse(txt_time.Text);  
        int_X =int.Parse(txt_X.Text);  
        int_Y = int.Parse(txt_Y.Text);  
        timer1.Interval = 3000;  
    }  

    //      
    private void btn_end_Click(object sender, EventArgs e)  
    {  
        timer1.Enabled = false;  
        timer1.Interval = 3000;  
    }  

    //         
    private void timer2_Tick(object sender, EventArgs e)  
    {  
        textBox1.Text= Cursor.Position.X.ToString();  
        textBox2.Text = Cursor.Position.Y.ToString();  
    }  

初めて自分のために奉仕できる小さなプログラムを書いたことを記録して、とても楽しかったです.△金貨を磨く行為は価値がなく、リターンが少なく、精力を浪費している.このブログを発表したのは、知識と私が自分のプログラムを通じて自分の考えを満たすことができる喜びを共有するためだけだ.