Windowsで動作する簡単なアプリケーションがあります。それは非常にシンプルなインターフェースを持っています:固定座標のボタンを備えたsqureウィンドウ。
このアプリケーションを利用するプログラムを作成する必要があります。それを起動し、ボタンの1つをクリックします(たとえば、(150,200)でクリックを呼び出します)。
Javaまたは.NETでそれを行う方法はありますか?
Windowsで動作する簡単なアプリケーションがあります。それは非常にシンプルなインターフェースを持っています:固定座標のボタンを備えたsqureウィンドウ。
このアプリケーションを利用するプログラムを作成する必要があります。それを起動し、ボタンの1つをクリックします(たとえば、(150,200)でクリックを呼び出します)。
Javaまたは.NETでそれを行う方法はありますか?
可能であれば、Hovercraft Full Of Eelsとして、autoitを使用する方がはるかに簡単です。AutoItがオプションでない場合は、それを行うためにwinAPI関数を使用する必要があります。
たとえば、座標でmouseclickを呼び出すには:
[DllImport("user32.dll")]
static extern bool SetCursorPos(int x, int y);
[DllImport("user32.dll")]
static extern bool GetCursorPos(ref Point lpPoint);
[DllImport("user32.dll")]
public static extern void mouse_event(int dwFlags, int dx, int dy, int cButtons, int dwExtraInfo);
public void LeftMouseClick(int xpos, int ypos) //Make a click at specified coords and return mouse back
{
Point retPoint = new Point();
GetCursorPos(ref retPoint); // set retPoint as mouse current coords
SetCursorPos(xpos, ypos); //set mouse cursor position
mouse_event(MOUSEEVENTF_LEFTDOWN, xpos, ypos, 0, 0);
mouse_event(MOUSEEVENTF_LEFTUP, xpos, ypos, 0, 0); //click made
SetCursorPos(retPoint.X, retPoint.Y); //return mouse position to coords
}
ただし、ウィンドウ内をクリックするには、ウィンドウが目の前にある必要があることに注意してください。たとえば、最小化されたアプリをクリックすることはできません。
試してみたい場合は、PInvokeで必要なすべての関数(プログラムの実行方法、hwndによる必要なウィンドウの取得など)を見つけることができます。
.Netの場合、私が好むAutomationElementをほとんど使用できます。少し学習時間がありますが、それほど時間はかからないはずです。ProcessStartInfoを使用してアプリを起動できます。
VS2010 ProまたはUltimateを使用している場合は、CodedUITestsを使用してボタンを数回押すことができます。
@Hovercraft Full Of Eelsが示唆したように-Autoit、Pythonは同じことをすることができます
はい-C#で..。
Process
てプロセスを開始します(これを行う方法については、Web上にたくさんのリソースがあります。ただし、これでうまくいかないことがいくつかあることに注意してください
.netでは、System.DiagnosticsからProcess.Startを実行してアプリケーションを起動したり、パラメーターを渡したり、P/Invokeを使用してマウスイベントをシミュレートしたりできます。SOにはすでにその答えがあります。
これが、ウィンドウをクリックして遊ぶための私の動作するテストアプリです。アプリを起動して、適切な場所でクリックすることを望んでいます)この方法でウィンドウをキャプチャするためのソリューションがあると便利です=)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Threading;
namespace ConsoleApplication8
{
class Program
{
static void Main(string[] args)
{
var startInfo = new ProcessStartInfo(@"C:\Users\Bodia\Documents\visual studio 2010\Projects\ConsoleApplication8\WindowsFormsApplication1\bin\Debug\WindowsFormsApplication1.exe");
startInfo.WindowStyle = ProcessWindowStyle.Maximized;
Console.WriteLine(1);
var process = Process.Start(startInfo);
Console.WriteLine(2);
Thread.Sleep(400);
Console.WriteLine(3);
LeftMouseClick(1000, 200);
Console.WriteLine(4);
}
static void CursorFun()
{
Point cursorPos = new Point();
GetCursorPos(ref cursorPos);
cursorPos.X += 100;
Thread.Sleep(1000);
SetCursorPos(cursorPos.X, cursorPos.Y);
cursorPos.X += 100;
Thread.Sleep(1000);
SetCursorPos(cursorPos.X, cursorPos.Y);
cursorPos.X += 100;
Thread.Sleep(1000);
SetCursorPos(cursorPos.X, cursorPos.Y);
cursorPos.X += 100;
Thread.Sleep(1000);
SetCursorPos(cursorPos.X, cursorPos.Y);
}
[DllImport("user32.dll")]
static extern bool SetCursorPos(int x, int y);
[DllImport("user32.dll")]
static extern bool GetCursorPos(ref Point lpPoint);
[DllImport("user32.dll")]
public static extern void mouse_event(int dwFlags, int dx, int dy, int cButtons, int dwExtraInfo);
public static void LeftMouseClick(int xpos, int ypos) //Make a click at specified coords and return mouse back
{
Point retPoint = new Point();
GetCursorPos(ref retPoint); // set retPoint as mouse current coords
SetCursorPos(xpos, ypos); //set mouse cursor position
mouse_event(MOUSEEVENTF_LEFTDOWN, xpos, ypos, 0, 0);
mouse_event(MOUSEEVENTF_LEFTUP, xpos, ypos, 0, 0); //click made
SetCursorPos(retPoint.X, retPoint.Y); //return mouse position to coords
}
struct Point
{
public int X;
public int Y;
}
private const int MOUSEEVENTF_LEFTDOWN = 0x02;
private const int MOUSEEVENTF_LEFTUP = 0x04;
private const int MOUSEEVENTF_RIGHTDOWN = 0x08;
private const int MOUSEEVENTF_RIGHTUP = 0x10;
}
}