×

Discussion Board

Results 1 to 5 of 5
  1. #1
    Regular Contributor
    Join Date
    Oct 2008
    Posts
    56

    Custom item - get key code?

    i got this in my custom item

    private int key;
    protected void keyPressed(int keyCode) {
    key = keyCode;
    this.repaint();
    }

    how do i know what key is "int key" ? like num key 6 or the key with the "c" letter?

    why are not there any enums or something in j2me?

  2. #2
    Nokia Developer Champion
    Join Date
    Nov 2007
    Location
    Rome, Italy
    Posts
    2,406

    Re: Custom item - get key code?

    Hi mikecotic,

    just check the CustomItem getGameAction() method and the game action constants defined in Canvas JavaDocs: by using these, you can easily check which key was pressed.

    Pit

  3. #3
    Regular Contributor
    Join Date
    Oct 2008
    Posts
    56

    Re: Custom item - get key code?

    this wont work ...

    Code:
        private int key;
        protected void keyPressed(int keyCode) {
            key = keyCode;
            if(Canvas.GAME_C ==keyCode)
            {
                //the "C" key was pressed , usally responisble for deleting
                //content / items . 
            }
            this.repaint();
        }

  4. #4
    Nokia Developer Champion
    Join Date
    Nov 2007
    Location
    Rome, Italy
    Posts
    2,406

    Re: Custom item - get key code?

    You have two errors in your code:

    * you have to retrieve the game action from the keyCode argument of the keyPressed() method, like this:
    Code:
    int gameAction = getGameAction(keyCode);
    and you have to use it when comparing with Canvas game action constants.

    * GAME_C does not represent the delete key, but is a generic "C" game button. Delete button has not an associated game action, so you have to implement a different mechanism to identify it. Here's a key codes table that could be useful:

    http://www.j2meforums.com/wiki/index...anvas_Keycodes

    Pit

  5. #5
    Regular Contributor
    Join Date
    Oct 2008
    Posts
    56

    Re: Custom item - get key code?

    works

    Code:
    keyCode == -8

Similar Threads

  1. Is there a bug with key code of "Enter"?
    By ahashim in forum Personal Profile
    Replies: 0
    Last Post: 2006-07-05, 11:04
  2. ARMI Template error
    By moldovan_catalin in forum Symbian
    Replies: 2
    Last Post: 2005-09-20, 07:39

Posting Permissions

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