×

Discussion Board

Results 1 to 14 of 14
  1. #1
    Registered User
    Join Date
    Mar 2006
    Posts
    28

    How to disable game/key sounds and how to make an "automatic" keypress?

    Is it possible to disable game/key sounds when running my midlet?

    How can I make an automatic repeated keypress? When I press some key it automaticly repeat its function until I press it again. I dont want to keep key pressed down all the time.
    Last edited by qwerty_wwd; 2006-09-19 at 13:56.

  2. #2
    Super Contributor
    Join Date
    Dec 2005
    Location
    Europe/Poland/Warsaw
    Posts
    1,697

    Re: How to disable game/key sounds and how to make a "automatic" keypress?

    hi,

    #1
    afaik thats not possible to disable sounds stright from midlet (java) - user need to use system preferences for that

    #2
    just use boolean flags fields changed everytime given key (game key) is pressed,
    set something to false or true and take correct action in your code depending if that flag is set to true or false. on next key/game key press change that flag to opposite value,

    regards,
    Peter

  3. #3
    Registered User
    Join Date
    Mar 2006
    Posts
    28

    Re: How to disable game/key sounds and how to make a "automatic" keypress?

    Thank you for your answers.

    I have tried that boolean thing and it worked fine until I tried to stop it. The phone doesn't registered my second keypress

    I plased my repeatable code in a while loop and looped that until second keypress. Should I try to run this loop in separate thread or what?

  4. #4
    Super Contributor
    Join Date
    Dec 2005
    Location
    Europe/Poland/Warsaw
    Posts
    1,697

    Re: How to disable game/key sounds and how to make a "automatic" keypress?

    hi,

    that should be extremely easy to just provide simple solution, here is not-so enhanced example - just Canvas.LEFT game key code is trapped:
    Code:
    import javax.microedition.midlet.*;
    import javax.microedition.lcdui.*;
    
    public class GameTest extends MIDlet implements CommandListener{
        public GameTest(){
            canvas = new GameCanvas();
            canvas.addCommand(new Command("Exit", Command.EXIT, 1));
            canvas.setCommandListener(this);
        }
        public void startApp() {
            Display.getDisplay(this).setCurrent(canvas);
        }
        
        public void pauseApp() {
        }
        
        public void destroyApp(boolean unconditional) {
            if(canvas != null){
                canvas.stop();
            }
        }
        
        public void commandAction(Command command, Displayable displayable) {
            if(command.getCommandType() == Command.EXIT){
                destroyApp(true);
                notifyDestroyed();
            }
        }
        
        private GameCanvas canvas;
        class GameCanvas extends Canvas implements Runnable{
            private boolean isMovingLeft = false;
            private Thread gameThread;
            public GameCanvas(){
                gameThread = new Thread(this);
                gameThread.start();
            }
            protected void paint(Graphics graphics) {
                graphics.setColor(0xFFFFFF);
                graphics.fillRect(0, 0, getWidth(), getHeight());
                String msg = (isMovingLeft == false) ? "no move detected" : "moving left";
                graphics.setColor(0x000000);
                graphics.drawString(msg, 0, 0, Graphics.TOP | Graphics.LEFT);
            }
            
            protected void keyPressed(int key){
                int keyCode = getGameAction(key);
                switch(keyCode){
                    case Canvas.LEFT:
                        isMovingLeft = !isMovingLeft;
                        break;
                }
            }
            
            public void run() {
                Thread currentThread = Thread.currentThread();
                while(currentThread == gameThread){
                    repaint();
                    try {
                        currentThread.sleep(500);
                    } catch (InterruptedException ex) {
                        // nothing
                    }
                }
            }
            
            public synchronized void stop(){
                gameThread = null;
            }
            
        }
    }
    there are other ways to implement the same,
    regards,
    Peter

  5. #5
    Registered User
    Join Date
    Mar 2006
    Posts
    28

    Re: How to disable game/key sounds and how to make a "automatic" keypress?

    Thanks again for your answer, but that isn't what I'm looking for. I ment that when I press e.g. LEFT key it automaticly repeats some function.

    I tried quikly to modify your code that you can realise what I mean.

    When you press LEFT first time it will set counter to -9 and isMovingLeft=true. Next time it will try to do what I want (increase counter automaticly until I press LEFT again) but it stucks that while loop.

    Code:
    import javax.microedition.midlet.*;
    import javax.microedition.lcdui.*;
    
    
    
    public class GameTest extends MIDlet implements CommandListener{
        public int counter=0;
        public GameTest(){
            canvas = new GameCanvas();
            canvas.addCommand(new Command("Exit", Command.EXIT, 1));
            canvas.setCommandListener(this);
        }
        public void startApp() {
            Display.getDisplay(this).setCurrent(canvas);
        }
        
        public void pauseApp() {
        }
        
        public void destroyApp(boolean unconditional) {
            if(canvas != null){
                canvas.stop();
            }
        }
        
        public void commandAction(Command command, Displayable displayable) {
            if(command.getCommandType() == Command.EXIT){
                destroyApp(true);
                notifyDestroyed();
            }
        }
        
        private GameCanvas canvas;
        class GameCanvas extends Canvas implements Runnable{
            private boolean isMovingLeft = false;
            private Thread gameThread;
            public GameCanvas(){
                gameThread = new Thread(this);
                gameThread.start();
            }
            protected void paint(Graphics graphics) {
                graphics.setColor(0xFFFFFF);
                graphics.fillRect(0, 0, getWidth(), getHeight());
                //String msg = (isMovingLeft == false) ? "no move detected" : "moving left";
                String msg = Integer.toString(counter);
                graphics.setColor(0x000000);
                graphics.drawString(msg, 0, 0, Graphics.TOP | Graphics.LEFT);
            }
            
            protected void keyPressed(int key){
                int keyCode = getGameAction(key);
                switch(keyCode){
                    case Canvas.LEFT:
                        while(isMovingLeft==true)
                            counter++;
                        
                        counter=-9;
                        isMovingLeft = !isMovingLeft;
                        break;
                }
            }
            
            public void run() {
                Thread currentThread = Thread.currentThread();
                while(currentThread == gameThread){
                    repaint();
                    try {
                        currentThread.sleep(500);
                    } catch (InterruptedException ex) {
                        // nothing
                    }
                }
            }
            
            public synchronized void stop(){
                gameThread = null;
            }
            
        }
    }

  6. #6
    Registered User
    Join Date
    Mar 2006
    Posts
    28

    Re: How to disable game/key sounds and how to make a "automatic" keypress?

    Can anyone help me?

  7. #7
    Regular Contributor
    Join Date
    Dec 2005
    Location
    Bangalore, India
    Posts
    90

    Re: How to disable game/key sounds and how to make a "automatic" keypress?

    in Symbian C++, we have
    CCoeEnv::SimulateKeyEventL() is there to simulate soft events.

    you can check if similar is there in Java.
    Best Regards
    -Boumitran

  8. #8
    Registered User
    Join Date
    Oct 2006
    Posts
    12

    Re: How to disable game/key sounds and how to make a "automatic" keypress?

    Dont really understand what you are trying to accomplish. On first entry into keyPressed you set isMovingLeft to true, then next time you loop until isMovingLeft is false but this is never the case so of course you get an infinite loop. Or am I missing something here? What do you want? Key repeats?

  9. #9
    Registered User
    Join Date
    Mar 2006
    Posts
    28

    Re: How to disable game/key sounds and how to make a "automatic" keypress?

    I want to make a repeated keypress function. When I press LEFT key it starts "infinite loop" and do that until I press that key again. But how can I make it stop that loop?

  10. #10
    Registered User
    Join Date
    Oct 2006
    Posts
    12

    Re: How to disable game/key sounds and how to make a "automatic" keypress?

    use "protected void keyRepeated(int arg0)" please forgive me but I really think you need to brush up your basic programming skills...

  11. #11
    Registered User
    Join Date
    Mar 2006
    Posts
    28

    Re: How to disable game/key sounds and how to make a "automatic" keypress?

    If I use "protected void keyRepeated(int arg0)" I have to keep that key pressed down that it will works. But I want press that key ONLY ONCE and it automaticly repeat it self UNTIL I press it again.

  12. #12
    Regular Contributor
    Join Date
    Oct 2009
    Posts
    97

    Unhappy Re: How to disable game/key sounds and how to make a "automatic" keypress?

    can we generate key sounds when I press a key in mobile keypad using carbide c++ or other language?please help me.

  13. #13
    Super Contributor
    Join Date
    Jun 2003
    Location
    Cheshire, UK
    Posts
    7,395

    Re: How to disable game/key sounds and how to make a "automatic" keypress?

    I'm not sure what you are asking.

    In Java ME, you can write an application that detectsa key press, and plays a sound, if that is what you mean.

    If you want to ask about C++, you need the C++ discussions.

    Graham.

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

    Re: How to disable game/key sounds and how to make a "automatic" keypress?

    Quote Originally Posted by somnath.das View Post
    can we generate key sounds when I press a key in mobile keypad using carbide c++ or other language?please help me.
    Hello,
    You know you are adding your query with such a older post. Was better if you could start a new thread for the same.
    Anyways Grahm's suggestion id quite good and you can follow the same if that was the issue.
    Thanks with Regards,

    R a j - The K e r n e l


    Join Delhi-NCR Nokia Developer's Community,

Posting Permissions

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