How to use a robot,it does't work
I would like to mimic keyboard using a Robot.In ButtonFrame,I need to put the focus in the 'blue' button and press it,but though the button has focus but failed to invoke the action.why?help me.ButtonFrame---the background color will change if you click different button related to a different color
package test6;
import javax.swing.*;
import java.awt.*;
import java.awt.event.InputEvent;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;
public class RobotTest
public static void main(String[] args)
EventQueue.invokeLater(new Runnable()
public void run()
// make frame with a button panel
ButtonFrame frame = new ButtonFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.requestFocus();
frame.setVisible(true);
// attach a robot to the screen device
GraphicsEnvironment environment = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice screen = environment.getDefaultScreenDevice();
try
Robot robot = new Robot(screen);
runTest(robot);
catch (AWTException e)
e.printStackTrace();
* Runs a sample test procedure
* @param robot the robot attached to the screen device
public static void runTest(Robot robot)
press(robot,KeyEvent.VK_TAB);
press(robot,' ');
public static void press(Robot r,int keycode){
r.keyPress(keycode);
r.keyRelease(keycode);
class ButtonFrame extends JFrame
public ButtonFrame()
setTitle("ButtonTest");
setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);
// create buttons
JButton yellowButton = new JButton("Yellow");
JButton blueButton = new JButton("Blue");
JButton redButton = new JButton("Red");
buttonPanel = new JPanel();
// add buttons to panel
buttonPanel.add(yellowButton);
buttonPanel.add(blueButton);
buttonPanel.add(redButton);
// add panel to frame
add(buttonPanel);
buttonPanel.setBackground(Color.green);
// create button actions
ColorAction yellowAction = new ColorAction(Color.YELLOW);
ColorAction blueAction = new ColorAction(Color.BLUE);
ColorAction redAction = new ColorAction(Color.RED);
// associate actions with buttons
yellowButton.addActionListener(yellowAction);
blueButton.addActionListener(blueAction);
redButton.addActionListener(redAction);
yellowButton.requestFocus();
* An action listener that sets the panel's background color.
private class ColorAction implements ActionListener
public ColorAction(Color c)
backgroundColor = c;
public void actionPerformed(ActionEvent event)
System.out.println("color:"+backgroundColor);
buttonPanel.setBackground(backgroundColor);
private Color backgroundColor;
private JPanel buttonPanel;
public static final int DEFAULT_WIDTH = 300;
public static final int DEFAULT_HEIGHT = 200;
}the app is easy to read,pls finish reading .thxs.
I think the main problem is that the Robot executes to fast. You need a delay between the tab and the space being pressed. I changed you main method to the following:
ButtonFrame frame = new ButtonFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.requestFocus();
frame.setVisible(true);
// attach a robot to the screen device
GraphicsEnvironment environment = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice screen = environment.getDefaultScreenDevice();
try
Robot robot = new Robot(screen);
robot.setAutoDelay(500);
runTest(robot);
catch (AWTException e)
e.printStackTrace();
}I also use KeyEvent.VK_SPACE.
Similar Messages
-
Brand new Mac user help please! How do you connect a 17" monitor to the MacBook? I have the monitor plugged into the Mac, but the F8 that I am used to with PC does not work. Please help. I am getting lots of spelling errors as the MacBook laptop screen is too small. Thank you so much! .
Contentmom6 wrote:
Brand new Mac user help please! How do you connect a 17" monitor to the MacBook? I have the monitor plugged into the Mac, but the F8 that I am used to with PC does not work.
Normally, you just connect the monitor to the MacBook using a VGA adaptor that you can buy from an Apple Store. Now try System Preferences > Displays > Detect Displays. You should now be able to select a display mode for the monitor. If it still doesn't work, then I'd check that everything is properly connected. I've had problems with colours disappearing due to a faulty connection in the VGA adaptor.
Bob -
I am trying to trigger a custom event using a program but does not work ..
HI ....i am trying to trigger a custom event of a custom object type using a program but does not work. If trigger the same event using SWUE it works.
below is the code...
{Key = '0010001115'. "Sales Order Number (hard-coded)
CALL FUNCTION 'SWE_EVENT_CREATE'
EXPORTING
objtype = 'ZXXXXXXXF'
objkey = KEY
event = 'ZEVENT'
CREATOR = ' '
TAKE_WORKITEM_REQUESTER = ' '
START_WITH_DELAY = ' '
START_RECFB_SYNCHRON = ' '
NO_COMMIT_FOR_QUEUE = ' '
DEBUG_FLAG = ' '
NO_LOGGING = ' '
IDENT =
IMPORTING
EVENT_ID =
RECEIVER_COUNT =
TABLES
EVENT_CONTAINER =
EXCEPTIONS
OBJTYPE_NOT_FOUND = 1
OTHERS = 2}
Please guide me if i am missing something.Hi Sunny,
I think you should try creating the event using FM SAP_WAPI_CREATE_EVENT.
CALL FUNCTION 'SAP_WAPI_CREATE_EVENT'
EXPORTING
OBJECT_TYPE = 'ZXXXXXXXF'
OBJECT_KEY = key
EVENT = 'ZEVENT'
* COMMIT_WORK = 'X'
* EVENT_LANGUAGE = SY-LANGU
* LANGUAGE = SY-LANGU
* USER = SY-UNAME
* IFS_XML_CONTAINER =
IMPORTING
RETURN_CODE = rcode
EVENT_ID = event_id
* TABLES
* INPUT_CONTAINER =
* MESSAGE_LINES =
* MESSAGE_STRUCT =
Regards,
Saumya -
How can use my Wireless Location Appliance to work with RF ID's?
How can use my Wireless Location Appliance to work with RF ID's for Asset Tagging.
It seems Smartcard used for ID cards have a small RF ID, can I use this for Asset Tagging?
Thanks in AdvanceThere are two kinds of RFID tags: Active tags, which have a battery or other internal power source, and passive tags, which have no power source and work by reflecting the energy from an RFID scanner (basically). At the energy levels and distances used for WiFi location detection, passive tags will not return a detectable signal.
Take a look at http://www.aeroscout.com/ for more info on WiFi RFID tagging. -
Recently purchased an unlocked iPhone4 handset only online. When my O2 sim card is used in handset it does not work. Any advice?
When you say it doesn't work, did it give you any type of message when you activated the phone with the O2 sim card?
-
"you are tring to use is a network resource that is unavailable. find folder itunes.msi" i dont have a folder like that and anything i use that is related does not work. ive tryed to uninstall but still does the same thing when.
Should the advice above not fix things for you...
For general advice see Troubleshooting issues with iTunes for Windows updates.
The steps in the second box are a guide to removing everything related to iTunes and then rebuilding it which is often a good starting point unless the symptoms indicate a more specific approach. Review the other boxes and the list of support documents further down the page in case one of them applies.
The further information area has direct links to the current and recent builds in case you have problems downloading, need to revert to an older version or want to try the iTunes for Windows (64-bit - for older video cards) release as a workaround for installation or performance issues, or compatibility with QuickTime or third party software.
Your library should be unaffected by these steps but there are also links to backup and recovery advice should it be needed.
tt2 -
How come the current view button does not work?
How come the current view button does not work?
Sorry, I have no idea what you are asking; please provide some details, and/or a screenshot if possible: https://forums.adobe.com/thread/1070933
-
Do I need creative Cloud to use Font Folio or does it work with CS6?
Do I need creative Cloud to use Font Folio or does it work with CS6?
The Adobe Font Folio has absolutely nothing to do with the Adobe Creative Cloud offering. I think you are thinking about TypeKit which is included with the Adobe Creative cloud, integrates with the Creative Cloud applications, but also allows use of the fonts therein with other applications.
The Adobe Font Folio is a disk with pretty much the entire Adobe Type Library. You install any number of fonts on the disk onto your system and they act just like any other fonts with any applications, including the CS6 applications.
- Dov -
TS3276 when I use cable my mail does not work. with wireless ok
when I use cable my mail does not work. with wireless ok
Unpower and restart it. If that doesn't help, try holding menu and left navigation keys TOGETHER for 6 secs.
AC -
How to use Java Robot to click the same button multiple times
Hi All,
I am trying to use Java Robot to turn a Windows utility located on the Desktop by clicking the same button on and then off with the following code:
1. Robot robot1 = new Robot();
2. robot1.mouseMove(400,180);
// Turn on the utility
3. robot1.delay(100);
4. robot1.mousePress(InputEvent.BUTTON1_MASK);
5. robot1.delay(100);
6. robot1.mouseRelease(InputEvent.BUTTON1_MASK);
//Wait for 2 minutes
7. robot1.delay(200);
// Move the mouse to disconnect button
8. robot1.mouseMove(400,180);
// Turn off the utility
9. robot1.mousePress(InputEvent.BUTTON1_MASK);
10. robot.delay(100);
11. robot.mouseRelease(InputEvent.BUTTON1_MASK);However, only the first click (line 1 - 7) worked. Everything from step 8 onwards doesn't appear to be doing anything. Even instantiating another robot2 to carry out step 8 - 11 did not work either. Also have tried running steps 9 - 11 only. ie skip 8.
My aim is to turn this tool on and off at regular interval.
Any assistance would be greatly appreciated.
Thanks in advance,
JackHi darth_code_r and Vincent,
Both you and Vincent are right about insufficient time between the release ( 6 ) of mouse button and step ( 9 ) press the same button again to turn it off. You are also correct in saying that it was not necessary to move the mouse again ( 8 ) since it was sitting on the right button already.
Below is the code I have ended up with which worked for me:
1. Robot robot1 = new Robot();
2. robot1.mouseMove(390,150);
4. robot1.mousePress(InputEvent.BUTTON1_MASK);
6. robot1.mouseRelease(InputEvent.BUTTON1_MASK);
//Wait for 3 minutes
7. robot1.delay(30000);
9. robot1.mousePress(InputEvent.BUTTON1_MASK);
11. robot1.mouseRelease(InputEvent.BUTTON1_MASK);This utility also takes a few seconds to turn itself on and vice versa. As a result, it is necessary to give it sufficient time to turn on prior to turning it off again with the second mouse press.
Thanks to both of you very much,
Jack -
Calling test sequence from CVI DLL that use ATL COM object does not work
I am trying to call some DLL function writen in CVI from teststand. The CVI DLL is using ATL COM object(Written by me).
The ATL COM object making instance of several ATL COM object inside it (including two controls that contains dialog). If I use a client writen in VC++ 6 and use the ATL COM (writen by me) works perfectly. But if I try to use it from CVI DLL it does not work any more.
What is wrong? The client is passing an IUnknow interface to my component. Can anybody explain me what is wrong?It is not clear from your question as to what is specifically failing. If possible, one option would be to remove TestStand from the picture and see if the problem still occurs using a CVI EXE that invokes the CVI DLL.
Scott Richardson - NI
Scott Richardson
National Instruments -
CODE ADDED using HTML Snippet Widget does not work
I am trying to add some code to a web page using the HTML Snippet widget and it does not work on my page. the code is as follows:
<script src='http://adn.ebay.com/files/js/min/ebay_activeContent-min.js'></script>
<script src='http://adn.ebay.com/cb?programId=1&campId=5336536214&toolId=10026&keyword= coinset+nationaruba&catId=11116&width=728&height=90&font=1&textColor=333366&linkColor=333333&a rrowColor=8BBC01&color1=B5B5B5&color2=FFFFFF'></script>
Can anyone help me to get this to work?
Thanks!
GreggI got this code from Ebay. It is an Ebay partner link.
Gregg -
How do I find out how to use cloud and what does it exactly do?
I Am new to Apple and just not sure how this iCloud works and what does it do.
Read here:
http://www.apple.com/icloud/
Basically it is a storage area on apple's servers that lets you keep a backup of your device to restore from in case you need to.
It also has additional features for your media content and other services. -
How to use Javascript Tools? does it has one for each branch?
I use jt cs5 and test a file like pic show, when run, it told document is not define.
what's wrong with it? function is as follow,
function f2c(s) {
var test = /(\d+(\.\d*)?)F\b/g; // 初始
return(s.replace
(test,
function($0,$1,$2) {
return((($1-32) * 5/9) + "C");
document.write(f2c("Water freezes at 32F and boils at 212F."));can't access to http://www.adobe.com/go/learn_ae_aeenhancershome
and,
btw, back to top thread,
the clue is document is indefine, why take place such problem?
document class shouldn't be included in the tools plateform?
have I to redefine this object again? -
trying to download creative cloud nothing downloads when trying photoshop getting an error and say retry
Yes, you need to install the Creative Cloud app first. It acts as your central hub for installation, sync and licensing.
Mylenium
Maybe you are looking for
-
How to keep up the session state values uncleared after page submit
hi, i am using Application Express 4.0.2.00.07 and 11g i have created a tabular form manually useing apex_items. select apex_item.checkbox(1,null) as "check", APEX_ITEM.DISPLAY_AND_SAVE(4,line_item_no) as "Line Item No", APEX_ITEM.DISPL
-
Receiver Determination ( MM - XI - SUS)
Hi, I have configured scenario MM-XI-SUS( Wherein i am sending Purchase oRder from MM system as Idoc to XI and then routing it to SUS via inbound Proxy). Here is the error in SXMB_MONI, I find all configuration for rcvr determination correct. Any ide
-
Where can a find a list in itunes of the computers/devices already authorised to my account?
-
Migrating FLOWS schema to linux box
We are in the process of migrating our database from Solaris to Linux. Our DBA found the following errors: SQL> select * from PHM_STREAMS_UNSUPPORTED_10_1; FLOWS_010306 DR$WWV_HELPTEXT_IDX$K 64 0 16 1073741825 unsupported column exists 100 YES FLOWS_
-
Upgrade from LR2 to LR4 - Have Photoshop CS5 Extended - LR adjustments now lost with RAW files
I have: Windows 7 64bit Lots of ram Lots of disk space Lots of everything I have CS5 Photoshop and LR2 - and all works perfectly. I import my RAW files from my Canon 5d2 - and I can edit and adjust - then if I need to export to PS to make further adj