Is there a way to programmatically identify the clear button on mobiles by using j2me?

222 views Asked by At

Is there a way to programmatically identify the clear button on mobiles like nokia, sony ericsson, LG, Samsung? Some mobiles having clear ("C") button and some mobiles doesn't have. I want to identify the clear button while my application running time. Is it possible?

2

There are 2 answers

2
funkybro On BEST ANSWER

@Dogbane's answer is a good starting point...

another trick is to observe that -8 is a common keyCode to represent Clear. So if you call canvas.getKeyName(-8), and no IllegalArgumentException is thrown, you know that there is a delete key.

So there's no exact science on this, but a combination of these two approaches should work most of the time.

1
dogbane On

You can call getKeyName. For example:

public void keyPressed(int keyCode) {
    if(getKeyName(keyCode).toUpperCase().indexOf("CLEAR") >= 0){
        //clear was pressed
    }
}