Accepting keys doesn't work

Hi,

unfortunately I’m unable to figure out how to “accept” a simple button press. I mean it works good, but not for german umlauts etc, for example it should print acceptedBut: ö after I press the Ö key several times.

Thanks for your help!

Greetings
Revington

Below is my example(Windows xp):

# -*- coding: cp1252 -*-
import sys


from direct.showbase.DirectObject import DirectObject
from panda3d import direct 
from panda3d.core import ButtonThrower
from panda3d.core import TextNode
from panda3d.core import CardMaker

from direct.directbase import DirectStart

class Keys(DirectObject):
    def __init__(self):      
        base.buttonThrowers[0].node().setKeystrokeEvent('stroked')
        self.accept('stroked', self.buttons,['stroked'])

        #text
        self.mes=TextNode('mes')
        self.mes.setAlign(TextNode.ACenter)
        self.mes.setText('press alt+f4 to exit')       
        self.textnode=aspect2d.attachNewNode(self.mes)
        self.textnode.setScale(0.1)
       
    def acceptedBut(self, but):
        print ("acceptedBut: " + but)
        
    def buttons(self,tag,but):

        out = but
        out = out.encode("utf8")
        
        self.mes.setText(out)
        base.accept(but, self.acceptedBut, [but])
            
        if but=='escape':
            sys.exit()
           
       
k=Keys()
run()

The method DirectObject is not a callback - it registers some function as a callback. Calling base.accept from within the callback method “buttons” doesn’t make any sense to me.

Try this:

    def buttons(self, key):
        out = key.encode('utf-8')
        self.mes.setText(out)
        print("accepted:", (key, out))
        if out == u'\x1b': # escape
            sys.exit()

What do you mean with method DirectObject? I thought it’s a class.

It’s supposed to make base accept any key that I pressed so that after someone hit a key, the next time acceptedBut would also be called for that key.

I tried to bind the Ö key that way but it didn’t work.

Sorry, I wanted to type DirectObject.accept.

You already register a handler for all keystrokes, the method “buttons”. So why registering a second handler for particular keys? Or do you just want to find out how to register a handler for only a single key?

Ah ok. Yes I’m trying to register a handler for a single key but something like self.accept(‘ö’, self.buttons,[‘stroked’]) etc didn’t work.

Thank you for your help!

As a side note the events set with base.buttonThrowers[0].node().setButtonDownEvent(‘bdown’) and base.buttonThrowers[0].node().setButtonUpEvent(‘bup’) are also not fired for noneascii keys, e.g. ÖÖÄß don’t trigger any of the above events. How can I get events for any of these keys?

It seems strange because I can enter any of the chars into a DirectEntry but I would like to use CEGUI so I need a way to accept events for these keys.

No one has any tips? :frowning:
I filed a bug report because it looks like one to me.