×

Discussion Board

Results 1 to 2 of 2
  1. #1
    Registered User
    Join Date
    Mar 2003
    Posts
    47

    Key event not working in 7650 simulator

    hello there

    i program and test a game which i develop in J2ME and test it on Erisson P800 simulator.... there is character on screen whcih can be controlled by arrow keys. i fully design and test the game on P800 simulator.. then i re compile the program using SUN ONE Studio for mobile and test it on 7650 simulator.... it seems to me that the key event is not being generated in the Canvas onject... here are some parts of the code....






    package Dragon;

    import javax.microedition.midlet.*;
    import javax.microedition.lcdui.*;
    import java.util.*;
    import java.io.*;
    import javax.microedition.io.*;

    public class SSCanvas extends Canvas
    {
    public boolean sleep;

    boolean leftKey, rightKey, upKey, downKey;


    protected void keyPressed(int keyCode)
    {
    // Get the game action from the key code
    int action = getGameAction(keyCode);

    if(action == LEFT)
    leftKey = true;
    else if(action == RIGHT)
    rightKey = true;
    else if(action == UP)
    upKey = true;
    else if(keyCode == DOWN)
    downKey = true;

    }



    protected void keyReleased(int keyCode)
    {
    // Get the game action from the key code
    int action = getGameAction(keyCode);

    if(action == LEFT)
    leftKey = false;
    else if(action == RIGHT)
    rightKey = false;
    else if(action == UP)
    upKey = false;
    else if(action == DOWN)
    downKey = false;

    }




    }



    as can be seen that on the key press event i set a variable to true. then on key release it is turn to false. in this way untill the key is pressed then the character continue to moves in that direction.



    ITS WORKING ON P800 Simulator why NOT 7650.


    Shahzad

  2. #2
    Regular Contributor
    Join Date
    Mar 2003
    Posts
    87

    RE: Key event not working in 7650 simulator

    I'm not sure why the code isn't working, but you can try using keyRepeated(int keyCode) which most of the new Nokias support. The method 'hasRepeatEvents()' can be used to determine if the device supports key repeating events.

    I hope this is a suitable alternative method.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •