java能实现模拟鼠标点击的吗

问题描述

就像外挂那样的 模拟打开软件 填写一些东西 模拟点击的 有知道怎么实现的吗?有人说能用junit做,不知道有人知道吗,有做过的吗?能否发个案例什么的。谢谢! 问题补充:谢谢楼上几位的指点,我是想知道大概怎么做。用什么实现,谢谢大家。比如说swing可以实现这个。

解决方案

junit是测试框架应该说的是AWT框架,你百度下就知道了
解决方案二:
上面贴的不对这个是模拟关闭文件的import java.awt.AWTException;import java.awt.Dimension;import java.awt.Robot;import java.awt.Toolkit;import java.awt.event.InputEvent;public class APP{public static void main(String[] args){try{Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();Robot robot = new Robot();robot.mouseMove(screenSize.width - 30, 5);robot.delay(1000);robot.mousePress(InputEvent.BUTTON1_MASK);robot.delay(300);robot.mouseRelease(InputEvent.BUTTON1_MASK);}catch (AWTException e){e.printStackTrace();}}}
解决方案三:
我看明白了,你是来控制鼠标和键盘,模拟实现人工点击对吧,使用swt下面是个例子import java.awt.MouseInfo;public class App extends JFrame implements KeyListener {private JLabel lblNewLabel;private String str = "";public App() {setDefaultCloseOperation(EXIT_ON_CLOSE);setLocationRelativeTo(null);setSize(400, 300);setResizable(false);getContentPane().setLayout(null);lblNewLabel = new JLabel("");lblNewLabel.setBounds(0, 259, 394, 13);getContentPane().add(lblNewLabel);setVisible(true);new Thread() {public void run() {while (true) {try {Point mainPoint = getLocation();Point point = MouseInfo.getPointerInfo().getLocation();int x = point.x - mainPoint.x;int y = point.y - mainPoint.y;if (x < 0 || x > 400) {sleep(10);continue;}if (y < 0 || y > 300) {sleep(10);continue;}lblNewLabel.setText(str + "x : " + x + " y : " + y);sleep(10);} catch (Exception e) {}}}}.start();this.addKeyListener(this);}public static void main(String[] args) {new App();}public void keyPressed(KeyEvent e) {if (e.getKeyCode() == KeyEvent.VK_CONTROL) {str = "C ";return;}if (e.getKeyCode() == KeyEvent.VK_SHIFT) {str = "S ";return;}str = "D ";}public void keyReleased(KeyEvent e) {str = "U ";}public void keyTyped(KeyEvent e) {}}
解决方案四:
public class FileChoose{ public static void main(String[] args) { JFileChooser chooser = new JFileChooser(); chooser.setCurrentDirectory(new File(".")); int result = chooser.showSaveDialog(null); chooser.setDialogTitle("0.0"); if(result==JFileChooser.APPROVE_OPTION); System.out.println(chooser.getSelectedFile().getPath()); }}
解决方案五:
junit只是一个java单元测试框架,要做的话就如ls的,要用swing之类来做
解决方案六:
import java.awt.*;import java.awt.event.*;import javax.swing.*;public class TestFrame extends JFrame { private JButton btn1 = new JButton("Button 1"); private JButton btn2 = new JButton("Button 2"); private Robot robot; public TestFrame() { setLayout(new GridLayout(0, 1)); add(btn1); add(btn2); btn1.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent event) { if (event.getButton() == MouseEvent.BUTTON1) System.out.println(btn1.getText() + "鼠标左键点击"); if (event.getButton() == MouseEvent.BUTTON3) System.out.println(btn1.getText() + "鼠标右键点击"); } }); btn2.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent event) { if (event.getButton() == MouseEvent.BUTTON1) System.out.println(btn2.getText() + "鼠标左键点击"); if (event.getButton() == MouseEvent.BUTTON3) System.out.println(btn2.getText() + "鼠标右键点击"); } }); addMouseMotionListener(new MouseMotionAdapter() { public void mouseMoved(MouseEvent event) { } }); } public void simulationClick() throws AWTException { //模拟鼠标点击代码 Point p1 = btn1.getLocation(); Point p2 = btn2.getLocation(); System.out.println(p1.x + "," + p1.y); System.out.println(p2.x + "," + p2.y); Point p = MouseInfo.getPointerInfo().getLocation(); int x = p.x; int y = p.y; robot = new Robot(); System.out.println(x + "," + y); robot.mouseMove(p1.x + 10, p2.y + 10); robot.mousePress(InputEvent.BUTTON1_MASK); robot.mouseRelease(InputEvent.BUTTON1_MASK); robot.mouseMove(x, y); } public static void main(String[] args) { EventQueue.invokeLater(new Runnable() { public void run() { TestFrame frame = new TestFrame(); frame.pack(); frame.setVisible(true); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); try { frame.simulationClick(); } catch (AWTException e) { e.printStackTrace(); } } }); }}

时间: 2024-09-20 05:55:21

java能实现模拟鼠标点击的吗的相关文章

位置-C# WPF WEBBROWSER 如根据指定的坐标处模拟鼠标点击事件

问题描述 C# WPF WEBBROWSER 如根据指定的坐标处模拟鼠标点击事件 C# WPF WEBBROWSER 如根据指定的坐标处模拟鼠标点击事件 SetCursorPos((int)clickPt.X, (int)clickPt.Y);//已屏幕为坐标点 // SetCursorPos((int)(this.Left + clickPt.X), (int)(this.Top + clickPt.Y));//已this窗体为坐标点 mouse_event((int)(MouseEventF

android 系统怎样实现 模拟鼠标点击事件

问题描述 我需做一个功能,让我的android系统能够实现一些智能演示操作,其中需要模拟鼠标点击事件,移动到指定坐标,再次实现点击功能. 解决方案 解决方案二:学习!解决方案三:发到android版块去吧.解决方案四:不懂android,帮顶祝你好运解决方案五:楼主实现了没求指教阿解决方案六:做出来没,求指教!!给份源代码撒解决方案七:用Instrumentation试试,这个有个安全限制真正解决,但对于不复杂的应该可以模拟鼠标点击事件等.解决方案八:楼主有demo没分享下非常感谢解决方案九:a

c# 在WebBrowser中用SendMessage模拟鼠标点击_实用技巧

复制代码 代码如下: using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.Runtime.InteropServices; namespace BrowserMouseClick { public

windows下python模拟鼠标点击和键盘输示例_python

需要先装pywin32,windows下调用winapi的接口 复制代码 代码如下: ## _*_ coding:UTF-8 _*___author__ = 'shanl' import win32apiimport win32conimport win32guifrom ctypes import *import time VK_CODE = {    'backspace':0x08,    'tab':0x09,    'clear':0x0C,    'enter':0x0D,    '

Python实现windows下模拟按键和鼠标点击的方法_python

本文实例讲述了Python实现windows下模拟按键和鼠标点击的方法.分享给大家供大家参考.具体如下: 这段代码可以模拟在窗口上按下按键.鼠标左键点击.鼠标右键点击.鼠标双击等等 # # _*_ coding:UTF-8 _*_ import win32api import win32con import win32gui from ctypes import * import time VK_CODE = { 'backspace':0x08, 'tab':0x09, 'clear':0x0

模拟鼠标操作,随机点击页面中url

问题描述 1.读取proxy.txt,里面为如下格式,代表代理服务器的地址和端口:12.12.12.12900012.12.12.12900012.12.12.1290002.按proxy.txt,随机选取一个代理服务器地址,设置为IE的代理服务器,设置好后,打开某特定网页,网页中,有很多的URL链接,然后,模拟鼠标操作,随机点击页面中url,一定时间后,关闭所有打开的IE页面.3.再换一个新的代理服务器地址,重复2该怎么实现呀,java可以做到吗?谢谢了! 解决方案 解决方案二:这个比较适合用

java响应鼠标点击事件的小程序

一个很基础的小程序,可以作为一种方法嵌入到其他应用中 import java.awt.Graphics;import java.awt.Event;import java.awt.Color;public class mouse extends java.applet.Applet{int num=0;//计数器初始化int px,py;public boolean mouseDown(Event evt,int x,int y)//鼠标按下事件{px=x;py=y;//鼠标按下时的坐标num+

模拟键盘-怎么在webbrowser中在鼠标点击的位置处得到焦点

问题描述 怎么在webbrowser中在鼠标点击的位置处得到焦点 我在webbrowser中载入淘宝界面,在搜索框处进行了模拟鼠标点击,我想在搜索框处获取焦点,然后模拟键盘输入文字.关键是焦点怎么获得.它不是控件,不能用this.控件.focus. 解决方案 我没试过,你看下面可以吗? 我的思路: 给文本框加载一个KeyPress事件,(例:enter事件) private void enter(object sender, KeyPressEventArgs e) { if (e.KeyCha

在java中如何获取在画布加载的图像上用鼠标点击的字符(图像上有很多字符)

问题描述 例如,我把一个小地图图像加载在canvas画布上,我鼠标点击小地图图像,怎么获取鼠标点击的地点(比如我点击的是火车站),java怎么知道我点的就是火车站,而不是其他地点的 解决方案 解决方案二:思路,给画布加入鼠标监听器addMouseListener,addMouseMotionListener,监听方法里event.getPoint()返回鼠标位置你的火车站,最起码要保留x,ywidthheight4个数据,可以建成Rectangle或其它形状(Shape的子类)Rectangle