zoukankan      html  css  js  c++  java
  • 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 }
  • 相关阅读:
    从小白到全栈的前端学习路径
    Vue初学者可能不知道的坑
    vue的基础使用
    15-浮动
    02-css的选择器
    深入理解JavaScript的闭包
    深入理解JavaScript的闭包,前戏— 作用域和词法作用域
    JavaScript简介
    02-HTML5新的input属性
    springboot+spring session+redis+nginx实现session共享和负载均衡
  • 原文地址:https://www.cnblogs.com/linbo3168/p/6590081.html
Copyright © 2011-2022 走看看