×

Discussion Board

Results 1 to 2 of 2
  1. #1
    Registered User
    Join Date
    Dec 2007
    Posts
    42

    Implementing Press-and-hold event ?

    hello everyone,

    can someone please help me with implementing press-and-hold key event? I want to hold a key for sometime to trigger a new function.
    i am using the class used in default.py to handle keyboard events.

    thanks

  2. #2
    Registered User
    Join Date
    Dec 2007
    Posts
    42

    Re: Implementing Press-and-hold event ?

    I tried to catch the number of repeating keys to implement press and hold event,but i think there is some error in the code.

    Code:
    class Keyboard(object):
        def __init__(self,onevent=lambda:None):
            self._keyboard_state={}
            self._downs={}
    	self._onevent=onevent	
    		
        def press_hold(self,scancode):
    	repeat=0
    	print repeat
    	while self.pressed(scancode):
    		if repeat==10:
    			 return True
    		print repeat 
    		repeat=repeat+1
    
        def handle_event(self,event):    
    	if event['type'] == appuifw.EEventKeyDown:
                code1=event['scancode']
                if not self.is_down(code1):
                    self._downs[code1]=self._downs.get(code1,0)+1
                self._keyboard_state[code1]=1
            elif event['type'] == appuifw.EEventKeyUp:
                self._keyboard_state[event['scancode']]=0
            self._onevent()
        def is_down(self,scancode):
            return self._keyboard_state.get(scancode,0)
        def pressed(self,scancode):
            if self._downs.get(scancode,0):
                self._downs[scancode]-=1
                return True
            return False
    Can someone look at it and tell me where am i making a mistake.

Similar Threads

  1. volume key event handling
    By whitewinds in forum Symbian Media (Closed)
    Replies: 4
    Last Post: 2009-05-13, 04:01
  2. How to Capture Press and Hold keyEvents
    By sriramadasu in forum Symbian
    Replies: 3
    Last Post: 2007-06-15, 13:15
  3. Replies: 8
    Last Post: 2003-07-11, 12:56
  4. Key press delay
    By dpolyakov in forum Mobile Java General
    Replies: 1
    Last Post: 2003-03-11, 12:57

Posting Permissions

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