Keyboard input other than base.accept?

I am implementing a command shell type gui class, and I don’t want to enter in pages of base.accept()s. Is there any way to accept all keydown events and have the ascii of the key that was pressed passed to the function?

You guys really need a better documentation on keyboard support. :confused:

I’m sure it’s possible to capture all keyboard events somehow, but if you want to make that kind of interface then you should be fine using DirectEntry as your input field.

For the record, you can do something like this:

base.buttonThrowers[0].node().setKeystrokeEvent('keystroke')
self.accept('keystroke', self.myFunc)
def myFunc(self, keyname):
    print keyname

to capture arbitrary keystrokes e.g. for a GUI input. But coppertop is right, a DirectEntry does this more automatically.

Also, for the record, there’s a conceptual difference between a “keystroke” and a “button”. A keystroke is a high-level concept; it’s a letter or symbol that you type as part of a word, as when typing text. It roughly corresponds to WM_CHAR in windows, and it includes international characters that you can only type with multiple keypresses. A keystroke does not generate up and down events, only keystroke events. A button is a physical button on the keyboard, which might or might not be similar to an ASCII letter. It has both a down and a corresponding up event. It roughly corresponds to WM_KEYDOWN and WM_KEYUP in windows.

If you want to receive button events instead of keystroke events, you can use:

base.buttonThrowers[0].node().setButtonDownEvent('buttonDown')
base.buttonThrowers[0].node().setButtonUpEvent('buttonUp')

The default is to throw a different event for each button-down and button-up event, because that is a common model for games. But you can enable these other event modes too.

Agreed. Would you like to write this for us?

David

On a related note, how do you set the pos of a DirectEntry box? Giving it a pos argument in the constructor throws this error:

Traceback (most recent call last):
  File "main.py", line 226, in <module>
    app = MyApp()
  File "main.py", line 192, in __init__
    self.console = Console(self,(-1,-.5),8)
  File "main.py", line 133, in __init__
    self.form = DirectEntry(text = "" ,scale=.05,command=self._receiveinput,init
ialText="", numLines = 2,focus=1,focusInCommand=clearfrom,pos=(0.95,-0.95))
  File "J:\Panda3D-1.7.2\direct\gui\DirectEntry.py", line 83, in __init__
    DirectFrame.__init__(self, parent)
  File "J:\Panda3D-1.7.2\direct\gui\DirectFrame.py", line 45, in __init__
    DirectGuiWidget.__init__(self, parent)
  File "J:\Panda3D-1.7.2\direct\gui\DirectGuiBase.py", line 756, in __init__
    apply(self.setPos, pos)
TypeError: NodePath.setPos() argument 1 must be NodePath, not float

This looks like a bug in panda…

EDIT: Boy am I slow, I didn’t see drwr’s post.
I would write it if I understood it. :stuck_out_tongue:

pos is a 3-d parameter, so you need to supply three parameters, even for a 2-d object like a DirectEntry. Use 0 for the y parameter, so use pos = (0.95, 0, -0.95).

David

Ah, that makes sense. Thanks a ton for your help guys. :smiley: