Java collation Software---java analog keyboard, mouse operation

Source: Internet
Author: User
1.Java Analog Keyboard Input Small demo, the realization of automatic Press: analog Ctrl+alt+z Press and lift
If you open QQ, then QQ will automatically play out. Haha, instead of manual operation;
Import Java.awt.Robot;
Import java.awt.event.KeyEvent;

public class Robotdemo
{
Private Robot Robot = null;

Public Robotdemo ()
{
Try
{
Robot = new Robot ();
}
catch (Awtexception e)
{
TODO auto-generated Catch block
E.printstacktrace ();
}
}

Simulate Ctrl+alt+z Press and lift
public void Keyboarddemo ()
{
Robot.keypress (Keyevent.vk_control);
Robot.keypress (Keyevent.vk_alt);
Robot.keypress (keyevent.vk_z);
Robot.keyrelease (Keyevent.vk_control);
Robot.keyrelease (Keyevent.vk_alt);
Robot.keyrelease (keyevent.vk_z);
}

public static void Main (string[] args)
{
Robotdemo demo = new Robotdemo ();
Demo.keyboarddemo ();
}
}
-------------------------------------------------------------------------
2. Try the Java Analog Space +ctrl button.
Press the key to see my code example:
public class Rebot extends Robot {
String s3= "";
Public Rebot () throws Awtexception {
Super ();
}

public void Yidong (int a, int b) {
This.mousemove (A, b);
}

public void zanting (int time) {
try {
New Thread (). Sleep (time);
catch (Interruptedexception e) {
TODO auto-generated Catch block
E.printstacktrace ();
}
}

public void Dianji () {
This.mousepress (Mouseevent.button1_mask);
This.mouserelease (Mouseevent.button1_mask);
}
public void Huiche () {
This.keypress (Keyevent.vk_enter);
This.keyrelease (Keyevent.vk_enter);
}
}
-------------------------------------------------------------------
Implementation of mouse simulation and keyboard mapping in 4.Java
Keywords: Java mouse emulation keyboard mapping
The robot class was implemented after Java SDK 1.3. This class is used to automate tests, run demo programs, and other needs control

Mouse and keyboard application raw-cost machine system input event. The main purpose of Robot is to facilitate the Java platform to implement its own

Dynamic test.
The difference between using this class to generate an input event and sending an event to an AWT event queue or an AWT component is that the event is in a flat

is generated in the native input queue of the console. For example, Robot.mousemove will actually move the mouse cursor instead of just generating

Mouse movement events.
The main methods of mouse and keyboard control in robot are:
void keyPress (int keycode) presses the given key.
void keyrelease (int keycode) frees the given key.
void MouseMove (int x, int y) moves the mouse pointer to a given screen coordinate.
void mousepress (int buttons) Press one or more mouse buttons.
void mouserelease (int buttons) frees one or more mouse buttons.
void MouseWheel (int wheelamt) rotates the wheel on the mouse with the wheel.
Below let us to combat mouse control, implementation of a simple mouse program Mousecontroller. Program features are

Simple: Move the mouse randomly and click left.
The code is as follows:
Import java.awt.AWTException;
Import java.awt.Dimension;
Import Java.awt.Robot;
Import Java.awt.Toolkit;
Import java.awt.event.InputEvent;
Import Java.util.Random;

/**
*
* @author Xiaofeng Wang
*/
public class Mousecontroller implements Runnable {
Private Dimension Dim;
Private Random Rand;
Private Robot Robot;
Private volatile Boolean stop = false;
/** creates a new instance of Main * *
Public Mousecontroller () {
Dim = Toolkit.getdefaulttoolkit (). Getscreensize ();
Rand = new Random ();
try {
Robot = new Robot ();
catch (Awtexception ex) {
Ex.printstacktrace ();
}
}

public void Run () {
while (!stop) {
int x = Rand.nextint (dim.width);
int y = rand.nextint (dim.height);
Robot.mousemove (x, y);
Robot.mousepress (Inputevent.button1_mask);
try {
Thread.Sleep (3000);
catch (Interruptedexception ex) {
Ex.printstacktrace ();
}
}
}
Public synchronized void Stop () {
Stop = true;
}
/** * @param args the command line arguments * *
public static void Main (string[] args) {
Mousecontroller mc = new Mousecontroller ();
Thread mcthread = new Thread (MC);
System.out.println ("Mouse Controller start");
Mcthread.start ();
try {
Thread.Sleep (60000);
catch (Interruptedexception ex) {
Ex.printstacktrace ();
}
Mc.stop ();
System.out.println ("Mouse Controller stoped");
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.