• KeyBoard 操作 !


    键盘操作:tab/ enter/ crtl+c ,crtl+v ;

     1 import java.awt.*;
     2 import java.awt.datatransfer.StringSelection;
     3 import java.awt.event.KeyEvent;
     4 
     5 /**
     6  * Created by ty on 2017/3/20.
     7  */
     8 public class KeyBoard {
     9 
    10     //设定剪切板并进行字符串黏贴的封装方法
    11     public static void setAndctrlVCipboardData(String string) {
    12         //模拟Ctrl+V  进行黏贴操作
    13         StringSelection stringSelection = new StringSelection(string);
    14         Toolkit.getDefaultToolkit().getSystemClipboard().setContents(stringSelection, null);
    15         Robot robot = null;
    16         try {
    17             robot = new Robot();
    18         } catch (AWTException el) {
    19             el.printStackTrace();
    20         }
    21         robot.keyPress(KeyEvent.VK_CONTROL);
    22         robot.keyPress(KeyEvent.VK_V);
    23         robot.keyRelease(KeyEvent.VK_V);
    24         robot.keyRelease(KeyEvent.VK_CONTROL);
    25         try {
    26             Thread.sleep(3000);
    27         } catch (Exception e) {
    28             e.printStackTrace();
    29         }
    30     }
    31     //按tab的封装方法
    32     public static void pressTabKey() {
    33         Robot robot = null;
    34         try {
    35             robot = new Robot();
    36         } catch (AWTException el) {
    37             el.printStackTrace();
    38         }
    39         robot.keyPress(KeyEvent.VK_TAB);
    40         robot.keyRelease(KeyEvent.VK_TAB);
    41     }
    42     //按Enter 键的封装
    43     public static void PressEnter(){
    44     Robot robot ;
    45         try {
    46             robot = new Robot();
    47             robot.keyPress(KeyEvent.VK_ENTER);
    48             robot.keyRelease(KeyEvent.VK_ENTER);
    49         } catch (AWTException e) {
    50             e.printStackTrace();
    51         }
    52 
    53 
    54     }
    55 
    56 
    57 }
  • 相关阅读:
    Java 标识符
    Java 关键字详解
    Java 语言的主要特性
    redis学习
    垃圾回收
    JVM内存结构
    sql总结(DML)
    sql总结(DDL)
    加密算法
    《数据结构》 定长顺序串常用操作代码集合
  • 原文地址:https://www.cnblogs.com/linbo3168/p/6590081.html
Copyright © 2020-2023  润新知