?
Solved

Get keypressed events in MIDlet

Posted on 2005-04-19
12
Medium Priority
?
1,848 Views
Last Modified: 2007-12-19
Hi i have a class which extends MIDlet, and have a form.

I want to do some action when the center-OK key is pressed within the form.

What can i do since in MIDlet keyPressed() event is never called?
0
Comment
Question by:MrTerrence
  • 4
  • 4
  • 2
  • +1
11 Comments
 
LVL 15

Expert Comment

by:aozarov
ID: 13821039
read http://developers.sun.com/techtopics/mobility/midp/articles/event/
You can either add CommandAction or handle raw key press.
0
 

Author Comment

by:MrTerrence
ID: 13821060
Hi,

maybe i repeat my question again

According to wat i noe,

setCommandListener only listen to events of the soft buttons, which triggers the commandAction function. While canvas listen to any low level key events, and trigger the keyPressed() event.

But i want my MIDlet form listen to keypressed, to do action when user clicked button on the keypad like "OK"...numeric keypad..etc...

wat shd i do?
0
 
LVL 9

Expert Comment

by:OBCT
ID: 13821148
>setCommandListener only listen to events of the soft buttons, which triggers the commandAction function
Yes thats true but the buttons that trigger the commandAction method will vary from phone to phone or vendor to vendor.
If theres an "OK" button, I would be supprised if it didn't trigger a commandAction.

May I ask what your trying to do?
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

Author Comment

by:MrTerrence
ID: 13821176
i m working on an motorola iDEN phone.

Wat i want to do is v v simple actually:

There's a Main menu form and a HELP screen form.

From the main menu MIDLet user can go into the HELP screen to see some explaination. There's a soft button "BACK" for user to go back to the main menu. I just want the screen to go BACK to main menu also if the user pressed the centre OK button besides the command button "BACK"...as simple as tat! But failed...bcoz no response at commandAction side when any keys (like 1.2.3...directions..ok..) other than the command buttons are pressed.
0
 
LVL 9

Expert Comment

by:OBCT
ID: 13821324
Unfortunately the only 2 options are the ones you already know of.
Either create a Canvas and handle things that way or use the 'standard' back button.
As I said before, command button implementations vary from phone to phone. Because of this, people become accustomed to using the same buttons for every application. Changing this may cause confusion to certain users.
0
 

Author Comment

by:MrTerrence
ID: 13830385
What about the CUstom Item?

I m not v sure but looks like if i can create a custom item and put it in the Form then that item can capture keyPressed() events?

0
 
LVL 9

Expert Comment

by:OBCT
ID: 13830520
Yes, this would work perfectly as long as you're using MIDP2.0.

>Unfortunately the only 2 options are the ones you already know of.

Ignore that comment :-p

This would be alot simpler than creating a Canvas AFAIK because there is a bunch of much needed functionality ready for you to use.
My appologies for not having noticed this before.
0
 
LVL 15

Expert Comment

by:aozarov
ID: 13830530
I think that should work as well.
0
 

Author Comment

by:MrTerrence
ID: 13924102
Hi all, i have confirmed that the only solution is to use custom item.

But it is pretty challenging also since the item must be always in focus in order to get the keyPressed() event. therefore i actually gave up the idea to capture centre-ok button key in a MIDlet Form.

But, to noe more abt how to capture keyPressed event using custom item, there's a discussion abt this issue here:

http://idendev.com/SCRIPTS/WA-motorola.EXE?A2=ind0504&L=sdklist&T=0&F=&S=&P=10450

0
 
LVL 9

Expert Comment

by:OBCT
ID: 13935412
I think this should be PAQ'd because MrTerrence did find a solution (although not a particularly easy one) and this could certain help other people in the future.
0
 

Accepted Solution

by:
CetusMOD earned 0 total points
ID: 13958718
PAQ'd, 100 points refunded.
CetusMOD
Community Support Moderator
0

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses

621 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question