2017-06-08 11 views
-2

私は知っている、このような多くの質問があります。しかし、私が読んだすべての答えは、私を助けなかった。だから私はここで尋ねる。ダブルクリックを実行するには?

マウスのダブルクリックを実行します。その前に私はすでにカーソルを正しい位置に設定しています:

Cursor.Position = new System.Drawing.Point(2225, 154); 

私がここで見つけたほぼすべてのクラスを使いましたが、誰も助けてくれませんでした。 (カーソルは設定されていましたが、ダブルクリックは行われませんでした)

誰でも私を助けることができます。ありがとう!

編集挨拶:私が使用 クラス:

using System; 
using System.Runtime.InteropServices; 

namespace AutoClicker 
{ 

    public class MouseSimulator 
    { 

     public void test_Click(System.Drawing.Point p) 
      { 
      //Move the mouse to the button position 

      //Perform button click. 
      INPUT structInput = new INPUT(); 
      structInput.type = SendInputEventType.InputMouse; 
      structInput.mkhi.mi.dwFlags = MouseEventFlags.ABSOLUTE | MouseEventFlags.LEFTDOWN | MouseEventFlags.LEFTUP; 
      structInput.mkhi.mi.dx = p.X; 
      structInput.mkhi.mi.dy = p.Y; 
      uint i = SendInput(1, ref structInput, Marshal.SizeOf(new INPUT())); 
     } 

     [DllImport("user32.dll")] 
     static extern IntPtr GetMessageExtraInfo(); 

     [DllImport("user32.dll", SetLastError = true)] 
     static extern uint SendInput(uint nInputs, ref INPUT pInputs, int cbSize); 

     [DllImport("user32.dll")] 
     static extern bool SetCursorPos(int X, int Y); 

     [Flags] 
     public enum MouseEventFlags 
     { 
      LEFTDOWN = 0x00000002, 
      LEFTUP = 0x00000004, 
      MIDDLEDOWN = 0x00000020, 
      MIDDLEUP = 0x00000040, 
      MOVE = 0x00000001, 
      ABSOLUTE = 0x00008000, 
      RIGHTDOWN = 0x00000008, 
      RIGHTUP = 0x00000010 
     } 

     /// <summary> 
     /// The event type contained in the union field 
     /// </summary> 
     enum SendInputEventType : int 
     { 
      /// <summary> 
      /// Contains Mouse event data 
      /// </summary> 
      InputMouse, 
      /// <summary> 
      /// Contains Keyboard event data 
      /// </summary> 
      InputKeyboard, 
      /// <summary> 
      /// Contains Hardware event data 
      /// </summary> 
      InputHardware 
     } 


     /// <summary> 
     /// The mouse data structure 
     /// </summary> 
     [StructLayout(LayoutKind.Sequential)] 
     struct MouseInputData 
     { 
      /// <summary> 
      /// The x value, if ABSOLUTE is passed in the flag then this is an actual X and Y value 
      /// otherwise it is a delta from the last position 
      /// </summary> 
      public int dx; 
      /// <summary> 
      /// The y value, if ABSOLUTE is passed in the flag then this is an actual X and Y value 
      /// otherwise it is a delta from the last position 
      /// </summary> 
      public int dy; 
      /// <summary> 
      /// Wheel event data, X buttons 
      /// </summary> 
      public uint mouseData; 
      /// <summary> 
      /// ORable field with the various flags about buttons and nature of event 
      /// </summary> 
      public MouseEventFlags dwFlags; 
      /// <summary> 
      /// The timestamp for the event, if zero then the system will provide 
      /// </summary> 
      public uint time; 
      /// <summary> 
      /// Additional data obtained by calling app via GetMessageExtraInfo 
      /// </summary> 
      public IntPtr dwExtraInfo; 
     } 

     [StructLayout(LayoutKind.Sequential)] 
     struct KEYBDINPUT 
     { 
      public ushort wVk; 
      public ushort wScan; 
      public uint dwFlags; 
      public uint time; 
      public IntPtr dwExtraInfo; 
     } 

     [StructLayout(LayoutKind.Sequential)] 
     struct HARDWAREINPUT 
     { 
      public int uMsg; 
      public short wParamL; 
      public short wParamH; 
     } 

     /// <summary> 
     /// Captures the union of the three three structures. 
     /// </summary> 
     [StructLayout(LayoutKind.Explicit)] 
     struct MouseKeybdhardwareInputUnion 
     { 
      /// <summary> 
      /// The Mouse Input Data 
      /// </summary> 
      [FieldOffset(0)] 
      public MouseInputData mi; 

      /// <summary> 
      /// The Keyboard input data 
      /// </summary> 
      [FieldOffset(0)] 
      public KEYBDINPUT ki; 

      /// <summary> 
      /// The hardware input data 
      /// </summary> 
      [FieldOffset(0)] 
      public HARDWAREINPUT hi; 
     } 

     /// <summary> 
     /// The Data passed to SendInput in an array. 
     /// </summary> 
     /// <remarks>Contains a union field type specifies what it contains </remarks> 
     [StructLayout(LayoutKind.Sequential)] 
     struct INPUT 
     { 
      /// <summary> 
      /// The actual data type contained in the union Field 
      /// </summary> 
      public SendInputEventType type; 
      public MouseKeybdhardwareInputUnion mkhi; 
     } 
    } 

} 

を、私はこのようにそれを使用:

System.Drawing.Point p = new System.Drawing.Point(2225, 154); 
     Cursor.Position = p; 
     MouseSimulator ms = new MouseSimulator(); 
     ms.test_Click(p); 
+0

をあなただけが示されたコードは、あなたが位置を変更していることを示し、どのようにあなたのダブルクリックを実行していますか?どのようにしてみましたか? –

+1

SendInput()を使用します。短い時間でボタンを2回上下させると、ダブルクリックが生成され、アプリケーションはそれを認識します。 –

+0

私は使用するクラスと私が使用した方法を追加しました。 –

答えて

0

あなたはtiがダブルクリックをシミュレートする必要がある場合は、必要に4 INPUTを使用してSendInput()を送信:

次のように

また、SendInput()を定義します。

static extern uint SendInput(uint nInputs, INPUT[] pInputs, int cbSize); 
+0

@DavidHeffernan改訂。ちょうど簡単な修正プログラムを作成しようとしました:p –

関連する問題