Hi Guys,
Did u ever hate the fact that the only way you can delete characters using the keyboard sensor is by pressing the darn backspace a million times?? Well no more is this an issue! Just use this script to type in your game exactly how windows is supposed to!
If you have any questions, let me know.
Cheers
#Blender SendKeys By ThunderCoast Inc.
#Script Purpose? This script is used to send keys to your game exactly how a normal windows computer should. By sending keys while holding a
#key, and best of all!! backspacing how windows computers should! I hope you enjoy this script as much i do.
#
#Cheers,
# Mod Corey
#Instructions:
# 1. Create a Text Object and toggle the Text property as a "String".
# Used as a target property for displaying text.
# 2. Add a boolean property named "Log" --> set it to "True".
# Used to turn on or off keysending for this object.
# 3. Add a string property named "TargetProp" --> set the string to the property you would like to add text to("Text" Recommended).
# Used for setting the property you would like to send text to.
# 4. Add a keyboard Sensor named "Keyboard"--> Set to true pulse mode 2 --> activate(AllKeys).
# Used for activating/deactivating this script.
# 5. Add a python controller --> Set this current Script Name.
# Used for setting this script to run.
# 6. Link the keyboard sensor to the python controller.
# Used to activate this script.
# 7. Happy Typing :)
#The three standard lines
gl = bge.logic
cont = gl.getCurrentController()
own = cont.owner
if own["Log"]:
#Get Keyboard events
keyboard = gl.keyboard.active_events
#Create global delay varialbe
try:
gl.TextDelay
except:
gl.TextDelay = 0
#Create Variables
keys = cont.sensors["Keyboard"]
ignore = [133, 131, 13]
delay = 8
#Check for shift key pressed
if 129 in keyboard or 128 in keyboard:
shift = 1
else:
shift = 0
#Check for keys pressed
for key in keyboard:
if keyboard[key] == 1:
#Turn On pulse mode
keys.usePosPulseMode = True
gl.TextDelay = 0
#Backspace Press
if 133 in keyboard:
own[own["TargetProp"]] = own[own["TargetProp"]][:-1]
#Tab Press
if 131 in keyboard:
own[own["TargetProp"]] += " "
#Enter Press
if 13 in keyboard:
own[own["TargetProp"]] += "
"
#Send Keys Tap
if keyboard[key] == 1 and key not in ignore:
own[own["TargetProp"]] += bge.events.EventToCharacter(key, shift)
#Send Keys Constant
elif gl.TextDelay >= delay and keyboard[key] == 2 and key not in ignore:
own[own["TargetProp"]] += bge.events.EventToCharacter(key, shift)
#Backspace
if 133 in keyboard:
if gl.TextDelay >= delay:
own[own["TargetProp"]] = own[own["TargetProp"]][:-1]
#Tab
if 131 in keyboard:
if gl.TextDelay >= delay:
own[own["TargetProp"]] += " "
#Enter
if 13 in keyboard:
if gl.TextDelay >= delay:
own[own["TargetProp"]] += "
"
#Turn off pulse mode
if keyboard == {}:
keys.usePosPulseMode = False
#Add 1 tick to time delay
gl.TextDelay += 1