Discussion Board

Results 1 to 5 of 5
  1. #1
    Regular Contributor mikecotic's Avatar
    Join Date
    Oct 2008
    Posts
    56
    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 jappit's Avatar
    Join Date
    Nov 2007
    Location
    Rome, Italy
    Posts
    2,391
    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 mikecotic's Avatar
    Join Date
    Oct 2008
    Posts
    56
    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 jappit's Avatar
    Join Date
    Nov 2007
    Location
    Rome, Italy
    Posts
    2,391
    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 mikecotic's Avatar
    Join Date
    Oct 2008
    Posts
    56
    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. Replies: 9
    Last Post: 2006-03-30, 08:36
  3. ARMI Template error
    By moldovan_catalin in forum Symbian C++
    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
  •  
Nokia Developer aims to help you create apps and publish them so you can connect with users around the world.

京ICP备05048969号  © Copyright Nokia 2013 All rights reserved