×

Discussion Board

Results 1 to 9 of 9

Thread: keypress matter

  1. #1
    Registered User
    Join Date
    Nov 2008
    Posts
    47

    keypress matter (urgent help)

    hi any idea why my key press when i run the application for the first time, it will be able to allow the image to move continuously when the key is press. but when i run the second time it does not work?

    Code:
      protected void keyPressed(int key) {
            keyCode = key;
            event = "Pressed";
            handleActions(key);
            repaint();
        }
    
        protected void keyRepeated(int key) {
            keyCode = key;
            event = "Repeated";
            handleActions(key);
            repaint();
        }
    
        protected void keyReleased(int key) {
            keyCode = key;
            event = "Released";
            repaint();
        }
    
        protected void pointerPressed(int x, int y) {
            this.x = x;
            this.y = y;
            keyCode = 0;
            event = "Pressed";
            repaint();
        }
        protected void pointerReleased(int x, int y) {
            this.x = x;
            this.y = y;
            keyCode = 0;
            event = "Released";
            repaint();
        }
    
        protected void pointerDragged(int x, int y) {
            this.x = x;
            this.y = y;
            keyCode = 0;
            event = "Dragged";
        }
    
        void handleActions(int keyCode) {
            int action = getGameAction(keyCode);
            switch (action) {
                case LEFT:
                x -= dx;
                break;
                case RIGHT:
                x += dx;
                break;
                case UP:
                y -= dy;
                break;
                case DOWN:
                y += dy;
                break;
                case FIRE:          
                     setX=x;
                        setY=y;
                      mustRepaint=false;
                      break;
                
                
            }
        }
    Last edited by intheworldofmyown; 2008-11-14 at 08:06. Reason: Need help urgently

  2. #2
    Super Contributor
    Join Date
    Mar 2008
    Location
    The Capital of INDIA
    Posts
    4,328

    Thumbs up Re: keypress matter

    Hi,
    Can you check and tell me where second time control is not coming..
    In kerpressed() or where..

    Only two reasons according to me-
    @ Either the Canvas is not set as current or is null.thats why keypressed will not be called at all..or
    @ It is coming in key pressed but but not entering in the conditions...

    you can put the println()and check what exactly is happening..
    Thanks,
    Thanks with Regards,

    R a j - The K e r n e l


    Join Delhi-NCR Nokia Developer's Community,

  3. #3
    Super Contributor
    Join Date
    Mar 2008
    Location
    The Capital of INDIA
    Posts
    4,328

    Thumbs up Re: keypress matter

    Hi,
    are you putting the println() in keypressed()..if not then put one and press the key and check whether the control is coming or not...

    Thanks,
    Thanks with Regards,

    R a j - The K e r n e l


    Join Delhi-NCR Nokia Developer's Community,

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

    Re: keypress matter (urgent help)

    Hi,

    in my opinion It has something to do with your mustRepaint variable (but cannot be sure about it, without seeing your repaint() method implementation).

    Try this slightly modified version of the handleActions() method:
    Code:
     void handleActions(int keyCode) {
            mustRepaint=true;
            int action = getGameAction(keyCode);
            switch (action) {
                case LEFT:
                x -= dx;
                break;
                case RIGHT:
                x += dx;
                break;
                case UP:
                y -= dy;
                break;
                case DOWN:
                y += dy;
                break;
                case FIRE:          
                      setX=x;
                      setY=y;
                      mustRepaint=false;
                      break;
                default:
                      mustRepaint=false;
                      break;
                
            }
        }
    Hope it helps,
    Pit

  5. #5
    Registered User
    Join Date
    Nov 2008
    Posts
    31

    Re: keypress matter

    sorry jappit,
    i switched to your code but doesn't work.
    it still doesn't do the keyRepeat actions

    Code:
    public boolean mustRepaint() {
            return mustRepaint;
        }
    the method is as simple as this.

    and it still cannot repeating call the methods when i hold down the buttons.

  6. #6
    Super Contributor
    Join Date
    Mar 2008
    Location
    The Capital of INDIA
    Posts
    4,328

    Thumbs up Re: keypress matter

    Hi,
    are you putting the println() in keypressed()..if not then put one and press the key and check whether the control is coming or not...
    and tell me what is happening...
    Thanks,
    Thanks with Regards,

    R a j - The K e r n e l


    Join Delhi-NCR Nokia Developer's Community,

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

    Re: keypress matter

    Hi shirodas,

    my guess was that, after the first FIRE key press, you was never setting the mustRepaint variable to true, but I was not that right obviously
    Anyway, try the debug methods proposed by Raj, otherwise post a more complete code, so that It'll be possible to debug it.

    Pit

  8. #8
    Regular Contributor
    Join Date
    Jul 2008
    Location
    Faridabad(Delhi NCR)
    Posts
    343

    Re: keypress matter

    HEy initialize all the value again ...as u hav done in starting i m sure it wil work
    Anshu Chauhan
    J2me Developer

  9. #9
    Super Contributor
    Join Date
    Mar 2008
    Location
    The Capital of INDIA
    Posts
    4,328

    Thumbs up Re: keypress matter

    Quote Originally Posted by shirodas View Post
    sorry jappit,
    it still doesn't do the keyRepeat actions
    and it still cannot repeating call the methods when i hold down the buttons.
    Hi shirodas,
    If you dont mind then can you please that..whether keyPressed() is not working.. second time or keyRepeated() is not working...
    You can put the code here...
    Thanks,
    Thanks with Regards,

    R a j - The K e r n e l


    Join Delhi-NCR Nokia Developer's Community,

Similar Threads

  1. [Announce] keypress module 1.0.5
    By y.a.k in forum Symbian
    Replies: 74
    Last Post: 2013-07-04, 17:40
  2. simulating keypress
    By selvynz in forum Symbian
    Replies: 28
    Last Post: 2010-08-20, 12:26
  3. Replies: 8
    Last Post: 2009-07-28, 03:38
  4. Replies: 2
    Last Post: 2007-10-18, 00:02
  5. Replies: 1
    Last Post: 2007-07-09, 04:09

Posting Permissions

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