Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Contributor
Posts: 36
Registered: ‎10-12-2012
My Device: developer
My Carrier: developer
Accepted Solution

how to use keydown and keyup events for a buttonfield

i want to continuously increment the gauge field when a button is in the  pressed form and stop incrementing it when it is released pls help

Developer
Posts: 16,986
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: how to use keydown and keyup events for a buttonfield

when a button is created with CONSUME_CLICK it propagates only a fieldchanged event when clicked, but without the style you can overwrite navigationClick and navigationUnclick to detect both events.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Contributor
Posts: 36
Registered: ‎10-12-2012
My Device: developer
My Carrier: developer

Re: how to use keydown and keyup events for a buttonfield

how can i detect the keydown and keyup event by overriding navigation click and unclick methods......
Developer
Posts: 16,986
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: how to use keydown and keyup events for a buttonfield

if you want to detect keys you can use http://www.blackberry.com/developers/docs/7.1.0api/net/rim/device/api/ui/component/ButtonField.html#... and http://www.blackberry.com/developers/docs/7.1.0api/net/rim/device/api/ui/component/ButtonField.html#...
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Contributor
Posts: 36
Registered: ‎10-12-2012
My Device: developer
My Carrier: developer

Re: how to use keydown and keyup events for a buttonfield

Actually i had read dis document but am not able to understand how to implement can u give me a small example or any reference......
Developer
Posts: 172
Registered: ‎01-02-2012
My Device: 8520 curve
My Carrier: compny

Re: how to use keydown and keyup events for a buttonfield

Hi krishna

 

implements the KeyListener interface in your class 

and override the keyUp and keyDown method by detecting the keycode for which key you are going to be realease .

 

Thanks

Contributor
Posts: 36
Registered: ‎10-12-2012
My Device: developer
My Carrier: developer

Re: how to use keydown and keyup events for a buttonfield

hi avinash

but how to get the keycode for a button that i have created.....
Developer
Posts: 172
Registered: ‎01-02-2012
My Device: 8520 curve
My Carrier: compny

Re: how to use keydown and keyup events for a buttonfield

class testkey implements KeyListener 

{

 

 

public boolean keyDown(int keycode, int time)
// terminate the game if the green or red keys are pressed
{
Dialog.alert("key value"+keycode);
return true;
}

}

 

this is just example do like this 

 

   in keydown method just display the keycode which is as argument of keyDown method and press the key you will get the integer value of that key then after you can use that keycode.

 

 

Thanks

 

 

 

if you got the solution fill free to accept it as solution.....

Developer
Posts: 16,986
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: how to use keydown and keyup events for a buttonfield

a buttonfield already implements keylistener, you don't have to implement it yourself.

overwrite keyUp and keyDown and handle its event, return true to indicate you have handled it, or super to pass it on.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Contributor
Posts: 36
Registered: ‎10-12-2012
My Device: developer
My Carrier: developer

Re: how to use keydown and keyup events for a buttonfield

 public MyScreen()
    {     
    	
        gauge1 = new GaugeField("", 0, 100, 0, gauge1.PERCENT);
       
        btn1 = new ButtonField("press",btn1.CONSUME_CLICK)
        {
        	public boolean keyDown(int keycode, int time) {
        		Dialog.alert("keyvalue"+keycode);
        		return false;
        	}

        };
        
       
        add(gauge1);
        add(btn1);
    }

 I have written the code like this but on clicking the buttonfield it is not showing any alert msg... on the otherhand when i press the escape key and menu key in the simulator its showing the keycode....help pls.. how to get the key code of the buttonfield btn1