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 }
  • 相关阅读:
    Python深入05 装饰器
    Python深入04 闭包
    Python深入03 对象的属性
    Ubuntu (虚拟机同样) 更换内核?
    .out
    GCC 编译详解
    linux 编译内核 /boot空间不足?
    Java Swing提供的文件选择对话框
    Java Swing 实时刷新JTextArea,以显示不断append的内容?
    为什么要编译Linux内核?
  • 原文地址:https://www.cnblogs.com/linbo3168/p/6590081.html
Copyright © 2011-2022 走看看