Skip to main content

simulate key presses..

7 replies [Last post]
gaganmalik
Offline
Joined: 2008-06-11
Points: 0

Hi fellows..
I was wondering is there a way to simulate key presses after loading a MIDlet or has anyone tried it yet? :)

Well, what I'm thinking is may be write a script that will have the sequence of key presses (with some delay in-between each) and if a parser module can be written which would read the file and generate key-press events for the emulator.
What are your views on this? and also can anyone guide me as to what modules/ part of the source code (phoneME feature) do I look into - basically for just generating & sending key-press events..

Thank you
- Gagan

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
terrencebarr
Offline
Joined: 2004-03-04
Points: 0

Gagan,

Here is an update:

After discussing this with some of our engineers it turns out we are internally already considering similar functionality - so it would make sense to develop this together as community project.

I'll find out more and let you know how this can proceed.

-- Terrence

gaganmalik
Offline
Joined: 2008-06-11
Points: 0

Sounds great.. :)

I'll be waiting to hear from you.. 'cause I want to delve into this as soon as possible..

leonidr
Offline
Joined: 2006-10-27
Points: 0

Hi,
We have Automation API in our implementation (that is, Sun's one) intended for automating various things and I just extended it to do what you've described: replaying events sequence stored in text file. Here how it works: Automation API comes with example Player MIDlet, which you can found at
src/automation/mvm/example/classes/com/sun/midp/automation/example/player, that takes three arguments:
- URL of MIDlet suite (jad or jar) to install and run
- URL of scenario file to use with MIDlet suite specified as first argument
- [optional] Double value for adjusting duration of all delay events inside scenario: the delays are divided by this value. So, specifying 2.0 as speed adjustment makes scenario replaying two times faster.

There is also sample scenario file, LWUITDemo.txt, for LWUITDemo MIDlet under "scenarios" directory.

In order to build that example MIDlet you have to use latest trunk and make sure that following build options are specified:
USE_MULTIPLE_ISOLATES=true USE_AUTOMATION=true USE_AUTOMATION_EXAMPLE=true

After building SJWC, you can lunch Player MIDlet with following command:
./runMidlet internal com.sun.midp.automation.example.Player [Speed adjustment]

For example, assuming that all files are stored on localhost:
./runMidlet internal com.sun.midp.automation.example.Player http://localhost/LWUITDemo.jad http://localhost/LWUITDemo.txt

This is just the first step in that direction. We have more things coming.

Leonid.

terrencebarr
Offline
Joined: 2004-03-04
Points: 0

Ah, ok, sorry I misunderstood the first time around.

Yes, I think that is possible ... and it would make a lot of sense as it is a valuable addition to phoneME as a validation and testing platform.

It's been a while since I looked that deep into either phoneME Feature or Advanced but I can't imaging injecting automated key presses can be that hard once you know where to look.

I suggest asking the specific question of which code to look at for platform key event handling on the phoneME Feature or Advanced forum ... once you know where to look you can investigate further yourself and prototype it.

If it proves possible to do that I would encourage you to start an official project to add this functionality to phoneME.

-- Terrence

gaganmalik
Offline
Joined: 2008-06-11
Points: 0

:) Thanks Terrence..

Since I'm working with phoneME feature as of now, I'll post in the other forum right away.

terrencebarr
Offline
Joined: 2004-03-04
Points: 0

The ability to inject key events into a MIDlet is limited for a couple of reasons, one being security.

The only way I am aware of is by calling the keyPressed() methods of low-level UI elemtens such as Canvas or CustomItem directly. So you could build a library with your parser that you link to your app. When your app starts the parser gets initialized and starts executing the script, calling keyPressed() accordingly. Note that this is not possible for high-level UI elements such as Form.

Hope this helps,

-- Terrence

gaganmalik
Offline
Joined: 2008-06-11
Points: 0

Hi Terrence,
thanks.. I understand that I'll have to link the parser module with the MIDlet and then invoke keyPressed(). This will have to be done for every App that is built.

But what I'm trying to do is integrate the parser module with phoneME (may be invoke it with a new command line option which would provide the script) such that after the MIDlet is installed and loaded, the parser runs parallel and reads the events, which are then sent to the MIDlet as keypress events.

Definitions of terms I've used here:
- Script: A sequence of keycodes OR keynames
- Parser Module: A module that is integrated with phoneME, which reads the 'Script' and generates appropriate events to be sent to the MIDlet.

(example: ok.. consider the WTK emulator. Now it has a GUI emulator. Now when u press a key on the num pad of the emulator, that 'button' press is read and sent from the emulator to the MIDlet.. right? Now, instead of the GUI transmitting the ;button' pressed events, I want to have a parser module that would read the script and generate these 'button' presses which would be sent to the MIDlet)

Is such a thing possible?

An example to start it could be specifying the script along with the autotester module, so that once the Test MIDlet loads, the parser can send the keypresses. The reason for doing this is to automate the testing of MIDlets and take the testing to a new level!

It'll be great to hear your as well others' views on this.. please discuss/suggest :)

- Gagan