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()
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?
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.