Sending Key Events

3 views
Skip to first unread message

a.t.obulreddy

unread,
Dec 1, 2010, 2:47:18 AM12/1/10
to jinjector
Hi Hello

can I send send the key Events in my test case like these
.Click() .Down() , .Up(), .Right(), .Left()
for that How i have to customize these key driven issues...?

-RAX-

unread,
Dec 1, 2010, 4:06:49 AM12/1/10
to jinjector
Hello there,

Yes you can.

To send a key event you simply have to cast the GUI element that will
receive the key event to its wrapper, then send it the key event.
Look at the methods here for instance:
http://code.google.com/p/jinjector/source/browse/trunk/jinjector_mobile/decorators_src/com/google/test/jinjector/j2me/wrapper/CanvasWrapper.java

To send an action (click) event you can use the fire command:
http://code.google.com/p/jinjector/source/browse/trunk/jinjector_mobile/decorators_src/com/google/test/jinjector/j2me/J2meUtil.java

An example of a command fired has been provided by Julian in the
download section.

Regards,
Michele

obulreddy at

unread,
Dec 3, 2010, 4:27:58 AM12/3/10
to jinj...@googlegroups.com
Hi michel.sama

thanks for giving suggestions....
I have done sending keys in my project.

I am not a developer.I dont know how to do canvas apps in development phase..
I have used But I have tried more and more times for automation of canvas apps
can you give a canvas example for to do this automation using
invokePointerDragged,invokePointerPressed,invokePointerReleased?


Thanks & Regards,

a.t.obulreddy,
Tejasoft Innovations Pvt Ltd.

> --
> You received this message because you are subscribed to the Google Groups "jinjector" group.
> To post to this group, send email to jinj...@googlegroups.com.
> To unsubscribe from this group, send email to jinjector+...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/jinjector?hl=en.
>
>

obulreddy at

unread,
Dec 3, 2010, 8:50:26 AM12/3/10
to jinj...@googlegroups.com
import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;

public class MySimple extends MIDlet
implements CommandListener {
private OurCanvas canv;
private boolean pause=false;
private boolean keepgoing=true;
private Display dsp;
private Command cmdq ;
public MySimple() {
cmdq = new Command("Quit", Command.EXIT, 0);
canv = new OurCanvas();
}

class OurCanvas extends Canvas implements Runnable
{
private int w, h;
OurCanvas(){
w = getWidth();
h = getHeight();
x = w/2 - 5;
y = h/2 - 5;
new Thread(this).start();
}
private int gs = 180 ;
public void paint(Graphics g) {
g.setGrayScale(255);
g.fillRect(0, 0, w, h );
g.setGrayScale(gs);
g.fillRect(x, y, 40, 20);
gs = 180 ;
}
int gx = -999;
public void keyPressed( int key ) {
gx = getGameAction(key) ;
pause=false;
}
public void keyReleased(int key) {
pause=true;
gx = -999;
}
public void run() {
while ( keepgoing ) {
if ( !pause ) {
switch ( gx ) {
case UP:
y -= dy; break;
case DOWN:
y += dy; break;
case LEFT:
x -= dx; break;
case RIGHT:
x += dx; break;
case FIRE:
gs = 104 ;
}
repaint();
}//end if
try {
Thread.sleep(40);
} catch (InterruptedException e) {}
}//end while
}
private int x;
private int y;
private int dx = 10;
private int dy = 10;
}//end canvas class

public void commandAction(Command c, Displayable s) {
if (c == cmdq) notifyDestroyed();
}
public void startApp() {
if (canv==null) canv = new OurCanvas();
canv.addCommand(cmdq);
canv.setCommandListener(this);
dsp = Display.getDisplay(this);
dsp.setCurrent(canv);
pause = false;
AlertType.INFO.playSound(dsp);
}
public void pauseApp() { pause = true; }
public void destroyApp(boolean b) { keepgoing = false; }
}import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;

public class MySimple extends MIDlet
implements CommandListener {
private OurCanvas canv;
private boolean pause=false;
private boolean keepgoing=true;
private Display dsp;
private Command cmdq ;
public MySimple() {
cmdq = new Command("Quit", Command.EXIT, 0);
canv = new OurCanvas();
}

class OurCanvas extends Canvas implements Runnable
{
private int w, h;
OurCanvas(){
w = getWidth();
h = getHeight();
x = w/2 - 5;
y = h/2 - 5;
new Thread(this).start();
}
private int gs = 180 ;
public void paint(Graphics g) {
g.setGrayScale(255);
g.fillRect(0, 0, w, h );
g.setGrayScale(gs);
g.fillRect(x, y, 40, 20);
gs = 180 ;
}
int gx = -999;
public void keyPressed( int key ) {
gx = getGameAction(key) ;
pause=false;
}
public void keyReleased(int key) {
pause=true;
gx = -999;
}
public void run() {
while ( keepgoing ) {
if ( !pause ) {
switch ( gx ) {
case UP:
y -= dy; break;
case DOWN:
y += dy; break;
case LEFT:
x -= dx; break;
case RIGHT:
x += dx; break;
case FIRE:
gs = 104 ;
}
repaint();
}//end if
try {
Thread.sleep(40);
} catch (InterruptedException e) {}
}//end while
}
private int x;
private int y;
private int dx = 10;
private int dy = 10;
}//end canvas class

public void commandAction(Command c, Displayable s) {
if (c == cmdq) notifyDestroyed();
}
public void startApp() {
if (canv==null) canv = new OurCanvas();
canv.addCommand(cmdq);
canv.setCommandListener(this);
dsp = Display.getDisplay(this);
dsp.setCurrent(canv);
pause = false;
AlertType.INFO.playSound(dsp);
}
public void pauseApp() { pause = true; }
public void destroyApp(boolean b) { keepgoing = false; }
}

I have done this example . But i dont know how to do wrapper objects
for this example
Can you give and write a simple test case how to start For a canvas
automation ....


Thanks & Regards,

a.t.ob...@gmail.com,
Tejasoft Innovations Pvt Ltd.

Reply all
Reply to author
Forward
0 new messages