Simple chat window, using getKeys, getCurrentlyPressedKeys, keymap, dictionary

I’m making a simple script to create a chat window, similar to bzoo, only simpler, for simpletons like myself.

Problem: getCurrentlyPressedKeys returns values that aren’t compatible with strings. Codes are all wrong

Solution: I made a key mapping dictionary.

First, complete this tutorial until you can see your text appear in-game:

Set the value of your Text property to “Press P to play” Now, attach this script to the plane you added earlier. Bind it to a sensor for “all keys”. Name it

import GameLogic as gl

if key<>None:
    if key[0][1]==1 and key[0][0]==13:
    if own.Text=="Press P to play":

    for j in key:
        if j[0]==128 or j[0]==129:
            if j[1]==1:
    if letter==133:
    elif letter in changed:
    elif letter > 32:
    if letter > 13:

Todo list:

Let me know if any of this interests you or check for source downloads, if they are ever ready for consumption…

  1. Create script to process keyboard input (done)
  2. Have letters appear on screen as you type (done)
  3. Create chat overlay window (todo)
  4. Build flexible threaded socket server for chat and games (done!)
  5. Create animated characters for game world (3 done).
  6. Log several clients into LAN game and see each other walking around (done!)

Wow. Your code is very well-written, but that functionality is already coded into the Keyboard Sensor. I started to write a tutorial about this a while ago and never published it…

I never got around to adding a section about making a flashing cursor or a section about context sensitive text input (like only accepting input when the specific text box is “in focus”).

(The tutorial is “Blender web plugin enhanced” and like all Blender web plugin content, it is best viewed in Internet Explorer.)

Yeah, it’ll be a lot easier if you use that functionality. But here’s a tip for anytime you need to use getPressedKeys or getCurrentlyPressedKeys:

if j == [[64,1]]:

That way you don’t have to worry about checking to see if it’s “none”.

Thanks, blendenzo. That’s quite a compliment coming from you. I wasn’t aware of how to use the log toggle property (or even what to ask) so thanks again. I’m just learning python so I’m trying to use concepts like lists and dictionaries while they are still fresh in my mind.

Well, I tried the logtoggle property and it works, except I can’t input some characters like the questionmark ? don’t show up when I type so I still have to use the script.