double key press / double tap

is there a way to register a double tap on the same button?

it doesn’t seem to be asked on the forums and i didn’t see it in the manual

well i might have searched the wrong terms on forum search function and missed out soem part in the manual…maybe, but i couldnt find any info on this

You can do this, but you have to write the code to do it yourself, for instance by checking globalClock.getFrameTime() each time you receive the button-press event, and checking to see if it is very close in time to the last time you received the same button-press event.

David

well thats saddening, so i have to set a time frame, like half a second

and within this time, if the key is down, and down again, it is detected as a double key press?

Yes, it’s easy to do. Something like this:

def handleKey(self):
    now = globalClock.getFrameTime()
    elapsed = now - self.lastKeyEvent
    self.lastKeyEvent = now
    if elapsed <= 0.5:
        self.handleDouble()
    else:
        self.handleSingle()

David

in the manual I see this code:

class ReadKeys(DirectObject.DirectObject):
  def __init__(self):
    self.accept('time-a-repeat', self.printRepeat)

  def printRepeat(self,a):
        print "repeat a",a

doesn’t that make the same work laperen asked for?

Repeat isn’t used for double-pressing. The repeat event is fired repeatedly if the button is held down.