Come from:http://bbs.51cto.com/thread-1097189-1.html
Function Description:
1. Open a Notepad
2. Maximize
3. Simulate key operation
The source code is posted:
Preview Source Code Print
| 001 |
Import java.awt.AWTException; |
| 002 |
Import Java.awt.Robot; |
| 003 |
Import Java.awt.Toolkit; |
| 004 |
Import Java.awt.datatransfer.Clipboard; |
| 005 |
Import java.awt.datatransfer.StringSelection; |
| 006 |
Import java.awt.datatransfer.Transferable; |
| 007 |
Import java.awt.event.KeyEvent; |
| 013 |
* <a href= "http://home.51cto.com/index.php?s=/space/2305405" target= "_blank" > @throws </a> awtexception |
| 015 |
public static void Main (string[] args) throws Exception { |
| 016 |
TODO auto-generated Method Stub |
| 017 |
Robot Robot = new Robot (); Create a Robot object |
| 018 |
Runtime.getruntime (). EXEC ("notepad"); Open a Notepad program |
| 019 |
Robot.delay (2000); Wait 2 seconds. |
| 021 |
Keypresswithalt (robot, Keyevent.vk_space); Press ALT + Space |
| 022 |
KeyPress (robot, keyevent.vk_x); Press the X key |
| 023 |
Robot.delay (1000); Wait 1 seconds. |
| 024 |
Keypressstring (robot, "Hello everyone, I am a small robot, I have a lot of skills." "); Input string |
| 025 |
Robot.delay (3000); Wait 3 seconds. |
| 026 |
KeyPress (robot, Keyevent.vk_enter); Press ENTER to change lines |
| 12V |
Keypressstring (Robot, "Now, I'll show you .....) Xi Hee "); Input string |
| 028 |
Robot.delay (3000); Wait 3 seconds. |
| 029 |
KeyPress (robot, Keyevent.vk_enter); Press ENTER to change lines |
| 030 |
Keypressstring (Robot, "First of all, I can press any of the keys on the keyboard.") Below, I press the A,B,C,D key Alone "); Input string |
| 031 |
KeyPress (robot, Keyevent.vk_enter); Press ENTER to change lines |
| 032 |
Robot.delay (3000); Wait 3 seconds. |
| 033 |
KeyPress (robot, KEYEVENT.VK_A); Press the A key |
| 034 |
Robot.delay (2000); Wait 2 seconds. |
| 035 |
KeyPress (robot, Keyevent.vk_b); Press the B key |
| 036 |
Robot.delay (2000); Wait 2 seconds. |
| 037 |
KeyPress (robot, Keyevent.vk_c); Press the C key |
| 038 |
Robot.delay (2000); Wait 2 seconds. |
| 039 |
KeyPress (robot, Keyevent.vk_d); Press the D key |
| 040 |
Robot.delay (2000); Wait 2 seconds. |
| 041 |
KeyPress (robot, Keyevent.vk_enter); Press ENTER to change lines |
| 042 |
Keypressstring (Robot, "hehe, finished ....") "); |
| 043 |
Robot.delay (3000); Wait 3 seconds. |
| 24v |
KeyPress (robot, Keyevent.vk_enter); Press ENTER to change lines |
| 045 |
Keypressstring (Robot, "En, on the above words a lot is not feel very messy ..." I'll clear it for you Now "); |
| 046 |
Robot.delay (2000); Wait 2 seconds. |
| 047 |
Keypresswithctrl (ROBOT,KEYEVENT.VK_A); Press CTRL + A to select all |
| 048 |
Robot.delay (2000); Wait 2 seconds. |
| 049 |
KeyPress (Robot,keyevent.vk_delete); Clear |
| 050 |
Robot.delay (3000); Wait 3 seconds. |
| 051 |
Keypressstring (Robot, "Well, now is not feel more refreshing and I will also press the key combination ..."); |
| 052 |
KeyPress (robot, Keyevent.vk_enter); Press ENTER to change lines |
| 053 |
Robot.delay (3000); Wait 3 seconds. |
| 054 |
Keypressstring (Robot, "........) Seems to have demonstrated it, hehe "); |
| 055 |
KeyPress (robot, Keyevent.vk_enter); Press ENTER to change lines |
| 056 |
Robot.delay (3000); Wait 3 seconds. |
| 057 |
Keypressstring (Robot, "in fact, I have a lot of skills, and now I do not show you ..."); |
| 058 |
KeyPress (robot, Keyevent.vk_enter); Press ENTER to change lines |
| 059 |
Robot.delay (3000); Wait 3 seconds. |
| 060 |
Keypressstring (robot, thank you ...). "); |