J2ME emulate keys

  • Thread starter Sebastien Dolbec
  • Start date
S

Sebastien Dolbec

Hello, I want to know if it's possible in J2ME to emulate keystrokes.
I'm currently developing on an I88S phone and I need to send keys
inside my program (Like KEY_NUM0, KEY_NUM1,etc.) and catching them
back like it was the user that has pressed them.

And naturally, if it's possible, how I can do that?

Thanks
 
T

Timo Kinnunen

Hello, I want to know if it's possible in J2ME to emulate keystrokes.
I'm currently developing on an I88S phone and I need to send keys
inside my program (Like KEY_NUM0, KEY_NUM1,etc.) and catching them
back like it was the user that has pressed them.

And naturally, if it's possible, how I can do that?

The methods (keyPressed, keyRepeated, keyReleased) are protected in Canvas,
so just call them yourself from the same package. Or you could make them
public.
 
S

Sebastien Dolbec

Timo Kinnunen said:
The methods (keyPressed, keyRepeated, keyReleased) are protected in Canvas,
so just call them yourself from the same package. Or you could make them
public.
If I understand, there is no other way to emulating keystrokes than
calling direcly keyPressed()? Do is it possible to send key events
like it was the user that had pressed the numeric pad without call
direcly the keypressed function?

thanks
 
T

Timo Kinnunen

If I understand, there is no other way to emulating keystrokes than
calling direcly keyPressed()? Do is it possible to send key events
like it was the user that had pressed the numeric pad without call
direcly the keypressed function?

No, there's no emulation API.
 
D

Darryl L. Pierce

Sebastien said:
Hello, I want to know if it's possible in J2ME to emulate keystrokes.
I'm currently developing on an I88S phone and I need to send keys
inside my program (Like KEY_NUM0, KEY_NUM1,etc.) and catching them
back like it was the user that has pressed them.

And naturally, if it's possible, how I can do that?

If you're trying to do that with the high-level UI widgets (TextField,
TextBox, List, ChoiceGroup) then the answer is that you *can't*. You can
only send such events to Canvas objects, as the the high-level UI widgets
give you no access to the actual key events.

--
/**
* @author Darryl L. Pierce <[email protected]>
* @see The J2ME FAQ <http://mypage.org/mcpierce/j2mefaq.html>
* @quote "What do you care what others think, Mr. Feynman?"
* @geek echo '$_ = "Jvtu bopuifs Pfsm ibdlfs."; y/a-z/za-y/; print' |
perl
*/
 
D

Darryl L. Pierce

Timo said:
The methods (keyPressed, keyRepeated, keyReleased) are protected in
Canvas, so just call them yourself from the same package. Or you could
make them public.

Those none of the high-level UI widgets extend Canvas. Form, TextBox and
List are *sibling* classes with Canvas, and Canvas introduces those methods
(i.e., it doesn't inherit them from Displayable and Displayable doesn't
have them).

--
/**
* @author Darryl L. Pierce <[email protected]>
* @see The J2ME FAQ <http://mypage.org/mcpierce/j2mefaq.html>
* @quote "What do you care what others think, Mr. Feynman?"
* @geek echo '$_ = "Jvtu bopuifs Pfsm ibdlfs."; y/a-z/za-y/; print' |
perl
*/
 
T

Timo Kinnunen

You could do it from a class running on a separate thread that has a
reference to the Canvas object.

Yeah, but a real emulation API should propably play a sound, turn on the
backlight and do all that other stuff which happens when a user presses a
key. I got the impression that it was these side-effects that the OP was
looking for, but perhaps I was mistaken.
 
D

Darryl L. Pierce

Timo said:
Yeah, but a real emulation API should propably play a sound, turn on the
backlight and do all that other stuff which happens when a user presses a
key. I got the impression that it was these side-effects that the OP was
looking for, but perhaps I was mistaken.

Perhaps. The OP didn't give enough information about what he means by
"emulate keystrokes". If it's as you suggest lighting up and playing a
keyclick then it's possible *if* the OEM provides an API for doing such
things. Sprint, for example, lets your play sounds and vibrate the handset,
and Motorola will let your light up the display (on some handsets).

Details, man! We need details! :)

--
/**
* @author Darryl L. Pierce <[email protected]>
* @see The J2ME FAQ <http://mypage.org/mcpierce/j2mefaq.html>
* @quote "What do you care what others think, Mr. Feynman?"
* @geek echo '$_ = "Jvtu bopuifs Pfsm ibdlfs."; y/a-z/za-y/; print' |
perl
*/
 
S

Sebastien Dolbec

Darryl L. Pierce said:
If you're trying to do that with the high-level UI widgets (TextField,
TextBox, List, ChoiceGroup) then the answer is that you *can't*. You can
only send such events to Canvas objects, as the the high-level UI widgets
give you no access to the actual key events.

Thank you, it's what I wanted to know.
 
Joined
Jun 29, 2009
Messages
2
Reaction score
0
Darryl L. Pierce said:
Timo Kinnunen wrote:

You could do it from a class running on a separate thread that has a
reference to the Canvas object.
How do you mean to do this?
I have the same problem:
thread = 3890614 post = 3890614 sorry for this but I am unable to send the url directly ...
("Java - key pressed on Form items?")
Regards,
Deksa
 

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,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top