robot keys not working

P

patrick

Hello,

Im trying to delete and clear a textfield in another application from a
java application.(before inserting my own digits) but the code below only
works some of the time.The cursor will end up at left of any digits in the
field with digits uncleared a lot of the time.

Any ideas why??

patrick


//click mouse in field first then press keys
robot.mouseMove(x,y);
robot.mousePress(InputEvent.BUTTON1_MASK );
robot.mouseRelease(InputEvent.BUTTON1_MASK );
//clear

//clear by back spacing
for(int i=0;i<15;i++)
{

robot.keyPress(KeyEvent.VK_RIGHT);robot.keyRelease(KeyEvent.VK_RIGHT);

robot.keyPress(KeyEvent.VK_RIGHT);robot.keyRelease(KeyEvent.VK_RIGHT);
}
for(int i=0;i<15;i++)
{

robot.keyPress(KeyEvent.VK_BACK_SPACE);robot.keyRelease(KeyEvent.VK_BACK_SPA
CE);

robot.keyPress(KeyEvent.VK_BACK_SPACE);robot.keyRelease(KeyEvent.VK_BACK_SPA
CE);
}


//the delete key should work this doesnt work at all i think.
// for(int i=0;i<15;i++)
// {
//
robot.keyPress(KeyEvent.VK_DELETE);robot.keyRelease(KeyEvent.VK_DELETE);
//
robot.keyPress(KeyEvent.VK_DELETE);robot.keyRelease(KeyEvent.VK_DELETE);
// }
 
P

patrick

patrick said:
Hello,

Im trying to delete and clear a textfield in another application from a
java application.(before inserting my own digits) but the code below only
works some of the time.The cursor will end up at left of any digits in the
field with digits uncleared a lot of the time.

Any ideas why??

patrick


//click mouse in field first then press keys
robot.mouseMove(x,y);
robot.mousePress(InputEvent.BUTTON1_MASK );
robot.mouseRelease(InputEvent.BUTTON1_MASK );
//clear

//clear by back spacing
for(int i=0;i<15;i++)
{

robot.keyPress(KeyEvent.VK_RIGHT);robot.keyRelease(KeyEvent.VK_RIGHT);

robot.keyPress(KeyEvent.VK_RIGHT);robot.keyRelease(KeyEvent.VK_RIGHT);
}
for(int i=0;i<15;i++)
{

robot.keyPress(KeyEvent.VK_BACK_SPACE);robot.keyRelease(KeyEvent.VK_BACK_SPA
robot.keyPress(KeyEvent.VK_BACK_SPACE);robot.keyRelease(KeyEvent.VK_BACK_SPA
CE);
}


//the delete key should work this doesnt work at all i think.
// for(int i=0;i<15;i++)
// {
//
//robot.keyPress(KeyEvent.VK_DELETE);robot.keyRelease(KeyEvent.VK_DELETE);
//robot.keyPress(KeyEvent.VK_DELETE);robot.keyRelease(KeyEvent.VK_DELETE);
// }
 
Joined
Nov 5, 2008
Messages
1
Reaction score
0
hope this helps

I too tried
r.keyPress(KeyEvent.VK_DELETE)
r.keyRelease(KeyEvent.VK_DELETE)

it didn't work.

then I tried selecting the item first and then deleting it.

r.mousePress(InputEvent.BUTTON1_MASK);
r.mouseRelease(InputEvent.BUTTON1_MASK);
r.keyPress(KeyEvent.VK_DELETE);
r.keyRelease(KeyEvent.VK_DELETE);

then it works!!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top