So, as detailed elsewhere, I’m trying to implement support for international keyboards via the use of raw-events.
I think that I’ve made some progress: I’ve managed to get what seem to be international keys picked up by Panda.
However, I’m facing something odd: the keys that I’m getting don’t always seem to match what I’m expecting, based on both typing in other programs and the OS-provided keyboard-layout image.
For example, if I select a Czech keyboard, the layout indicates that the “3”-key should produce the “š”-character. And in most places, it does–that’s how I entered it in that sentence, in fact.
In a Panda-program, however, that key is only recognised as “3”, even after application of “getMappedButtonLabel”.
Conversely, the “0”-key correctly produces the “é”-character, both in places like this text-entry box and in Panda.
So, am I doing something wrong? Is it an issue with the default font?
Here is the code that I’m using right now, more or less:
from direct.showbase.ShowBase import ShowBase
from panda3d.core import TextNode
from direct.gui.DirectGui import *
from panda3d import __version__ as pandaVersion
print (pandaVersion)
import sys
print (sys.version)
class Game(ShowBase):
def __init__(self):
ShowBase.__init__(self)
self.disableMouse()
self.accept("escape", base.userExit)
self.txt = DirectLabel(text = "Mew",
scale = 0.15)
self.buttonThrower = base.buttonThrowers[0].node()
self.buttonThrower.setRawButtonDownEvent("keyInterception")
self.accept("keyInterception", self.keyInterception)
self.keyMap = base.win.get_keyboard_map()
def keyInterception(self, key):
self.accept("raw-" + key, self.keyEvent, extraArgs = [key])
self.updateKeyText("KEY BOUND!\nKey: {0}\nHaving label: {1}", key)
self.buttonThrower.setRawButtonDownEvent("")
def keyEvent(self, key):
self.updateKeyText("A key was pressed!\nThat being: {0}\nWith label: {1}", key)
def updateKeyText(self, message, key):
mew = self.keyMap.getMappedButtonLabel(key)
if len(mew) == 0:
mew = key
self.txt.show()
self.txt["text"] = message.format(key, mew)
self.txt.resetFrameSize()
app = Game()
app.run()
In short, it first listens for any key, then, on a key being pressed, clears the “any key” event and binds a raw-event for the key in question. Both the binding and subsequent presses of the bound key display messages to indicate that they were enacted, and with what data.
(This won’t work for things like mouse-buttons, of course, but right now I’m concentrating on the keyboard.)