QQ远程功能很适合远程维护,考虑到下班后需要维护系统,需要一个自动远程的程序。
QQ上获取文本框的内容不知道如何取得,只好使用笨笨的 控制鼠标复制粘贴,检查粘贴板来实现
先修改QQ用户备注为 远程QQ
com.sun.jna.platform.win32.WinDef.HWND hwnd = User32.INSTANCE.FindWindow("TXGuiFoundation", "远程QQ");
if (hwnd==null) {
System.err.println("未发现 [远程QQ] QQ对话框");
System.exit(0);
}
获得QQ对话框中的内容,就是全选 和复制
try {
Thread.sleep(10000);
User32.INSTANCE.ShowWindow(hwnd, 1);
Rect rect = new Rect(); //窗口位置
User32.INSTANCE.GetWindowRect(hwnd, rect); //获得窗口位置
moveClickMouse(hwnd, MouseHook.WM_RBUTTONDOWN, margin, +0xb4); //点击 右键
moveClickMouse(hwnd, MouseHook.WM_RBUTTONUP, margin, +0xb4);
Thread.sleep(1000);
com.sun.jna.platform.win32.WinDef.HWND childHwnd =
MyUser32.INSTANCE.WindowFromPoint(rect.getLeft() +margin + 0x22, rect.getTop() + 0xb4 + 0x24);
moveClickMouse(childHwnd, MouseHook.WM_LBUTTONDOWN, +0x22, 0x24); //
moveClickMouse(childHwnd, MouseHook.WM_LBUTTONUP, 0x22, 0x24); //
Thread.sleep(1000);
moveClickMouse(hwnd, MouseHook.WM_RBUTTONDOWN, margin, +0xb4); //点击 右键
moveClickMouse(hwnd, MouseHook.WM_RBUTTONUP, margin, +0xb4);
Thread.sleep(1000);
childHwnd =
MyUser32.INSTANCE.WindowFromPoint(rect.getLeft() + margin + 0x22, rect.getTop() + 0xb4 + 0x12);
moveClickMouse(childHwnd, MouseHook.WM_LBUTTONDOWN, +0x22, +0x12);
moveClickMouse(childHwnd, MouseHook.WM_LBUTTONUP, +0x22, +0x12);
Thread.sleep(1000);
Thread.sleep(10000);
User32.INSTANCE.ShowWindow(hwnd, 1);
Rect rect = new Rect(); //窗口位置
User32.INSTANCE.GetWindowRect(hwnd, rect); //获得窗口位置
moveClickMouse(hwnd, MouseHook.WM_RBUTTONDOWN, margin, +0xb4); //点击 右键
moveClickMouse(hwnd, MouseHook.WM_RBUTTONUP, margin, +0xb4);
Thread.sleep(1000);
com.sun.jna.platform.win32.WinDef.HWND childHwnd =
MyUser32.INSTANCE.WindowFromPoint(rect.getLeft() +margin + 0x22, rect.getTop() + 0xb4 + 0x24);
moveClickMouse(childHwnd, MouseHook.WM_LBUTTONDOWN, +0x22, 0x24); //
moveClickMouse(childHwnd, MouseHook.WM_LBUTTONUP, 0x22, 0x24); //
Thread.sleep(1000);
moveClickMouse(hwnd, MouseHook.WM_RBUTTONDOWN, margin, +0xb4); //点击 右键
moveClickMouse(hwnd, MouseHook.WM_RBUTTONUP, margin, +0xb4);
Thread.sleep(1000);
childHwnd =
MyUser32.INSTANCE.WindowFromPoint(rect.getLeft() + margin + 0x22, rect.getTop() + 0xb4 + 0x12);
moveClickMouse(childHwnd, MouseHook.WM_LBUTTONDOWN, +0x22, +0x12);
moveClickMouse(childHwnd, MouseHook.WM_LBUTTONUP, +0x22, +0x12);
Thread.sleep(1000);
View Code
/**
* 软移动单击鼠标
*
* @param hWnd 窗口句柄
* @param msg 消息类型
* @param x X坐标
* @param y Y坐标
*/
public static void moveClickMouse(WinDef.HWND hWnd, int msg, int x, int y) {
WinDef.WPARAM wParam = new WinDef.WPARAM(0);
int temp = y << 16 | (x << 16 >> 16);
WinDef.LPARAM lParam = new WinDef.LPARAM(temp);
WinDef.UINT_PTR uint = new WinDef.UINT_PTR(msg);
User32.MSG msg1 = new User32.MSG();
User32.INSTANCE.PostMessage(hWnd, msg, wParam, lParam);
}
* 软移动单击鼠标
*
* @param hWnd 窗口句柄
* @param msg 消息类型
* @param x X坐标
* @param y Y坐标
*/
public static void moveClickMouse(WinDef.HWND hWnd, int msg, int x, int y) {
WinDef.WPARAM wParam = new WinDef.WPARAM(0);
int temp = y << 16 | (x << 16 >> 16);
WinDef.LPARAM lParam = new WinDef.LPARAM(temp);
WinDef.UINT_PTR uint = new WinDef.UINT_PTR(msg);
User32.MSG msg1 = new User32.MSG();
User32.INSTANCE.PostMessage(hWnd, msg, wParam, lParam);
}
分析系统粘贴板的内容
View Code
for (;;){
Clipboard clipboard = java.awt.Toolkit.getDefaultToolkit().getSystemClipboard();
java.awt.datatransfer.Transferable transferable=clipboard.getContents(apitest.class);
clipboard.setContents(transferable, null);
GetWindowText(hwnd) ;
java.awt.datatransfer.DataFlavor flavor=java.awt.datatransfer.DataFlavor.stringFlavor;
if(transferable.isDataFlavorSupported(flavor))
{
try
{
String str=(String)transferable.getTransferData(flavor);
System.err.println(str);
if (str.contains("callme!!!")){
ClearQQ(hwnd);
moveClickMouse(hwnd, WM_LBUTTONDOWN, 0x14f-38, 0x7e-58); //点击远程
moveClickMouse(hwnd, WM_LBUTTONUP,0x14f-38,0x7e-58);
break;
}
}
catch(Exception ee)
{
ee.printStackTrace();
}
}
}
Clipboard clipboard = java.awt.Toolkit.getDefaultToolkit().getSystemClipboard();
java.awt.datatransfer.Transferable transferable=clipboard.getContents(apitest.class);
clipboard.setContents(transferable, null);
GetWindowText(hwnd) ;
java.awt.datatransfer.DataFlavor flavor=java.awt.datatransfer.DataFlavor.stringFlavor;
if(transferable.isDataFlavorSupported(flavor))
{
try
{
String str=(String)transferable.getTransferData(flavor);
System.err.println(str);
if (str.contains("callme!!!")){
ClearQQ(hwnd);
moveClickMouse(hwnd, WM_LBUTTONDOWN, 0x14f-38, 0x7e-58); //点击远程
moveClickMouse(hwnd, WM_LBUTTONUP,0x14f-38,0x7e-58);
break;
}
}
catch(Exception ee)
{
ee.printStackTrace();
}
}
}
目前的问题是粘贴板好像循环两次才能正确赋值,不是很清楚原因。
https://files.cnblogs.com/cndavy/QQRobert.jar.zip 下载后 去掉.zip
java -jar QQRobert.jar