package com.dzx; import java.awt.*; import java.awt.event.InputEvent; /** * BUTTON3_DOWN_MASK 鼠标右键 * BUTTON1_DOWN_MASK 鼠标左键 * BUTTON2_DOWN_MASK 鼠标滚轮??? * VK_HOME Home键 * VK_CONTROL 控制键 * VK_END End键 * VK_SHIFT shift键 * VK_PGUP page up键 * VK_BACK_SPACE 退格键 * VK_PGDN page down键 * VK_CAPS_LOCK 大小写锁定键 * VK_UP 上箭头 * VK_NUM_LOCK 小键盘锁定键 * VK_DOWN 下箭头 * VK_ENTER 回车键 * VK_LEFT 左箭头 * VK_UNDEFINED 未知键 * VK_RIGHT 右箭头 * VK_F1--VK_F12 F1 -- F12 * VK_ESCAPE Esc键 * VK_0 --VK_9 0 --- 9 * VK_TAB Tab键 * VK_A --VK_Z A----Z */ public class RobotMain { public static void main(String[] args) { Dimension screensize = Toolkit.getDefaultToolkit().getScreenSize(); int width = (int)screensize.getWidth(); int height = (int)screensize.getHeight(); System.out.println("width="+width+",height="+height); try { Robot robot = new Robot(); robot.mouseMove(720, 450); robot.delay(1000); robot.mousePress(InputEvent.BUTTON1_DOWN_MASK); robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK); //获取屏幕指定位置的颜色 Color pixelColor = robot.getPixelColor(720, 450); System.out.println(pixelColor); // robot.keyPress(KeyEvent.VK_CAPS_LOCK); // robot.keyRelease(KeyEvent.VK_CAPS_LOCK); // robot.keyPress(KeyEvent.VK_A); // robot.keyRelease(KeyEvent.VK_A); } catch (AWTException e) { e.printStackTrace(); } } }
Java 模拟电脑鼠标键盘操作
最新推荐文章于 2024-05-24 22:10:38 发布