GameLogic.keyboard.inputs not working?

If I try and use GameLogic.keyboard.inputs, and check if the active state equals to a keyboard key (Up arrow key) in the globalDict, that works, but no result (movement) is produced. It worked fine in 2.79, so did I do something wrong, or did something screw up? I know keyboard.inputs is basically events but for UPBGE.

Can you show your code? Input should look something like this:

import bge

def main(self):
    
    if bge.logic.keyboard.inputs[bge.events.UPARROWKEY].active:
        print("Key was pressed.")

Additionally, when working with the globalDict module, you might need to convert saved data to string, if you haven’t already.

A good example of what I am trying to achieve would be this - move the cube with the uparrow key.

import bge
import GameKeys as gk
import bge.logic as gl
kb = gl.keyboard
inputs = kb.inputs
ACTIVE = gl.KX_INPUT_ACTIVE
INACTIVE = gl.KX_INPUT_NONE

def main(cont):

   own = cont.owner
   dict = gl.globalDict()
   move = cont.actuators('motion_py')
   KEY_UP = {'up',gk.UPARROW_KEY} # Is this correct?

   if ACTIVE == kb.inputs[dict[KEY_UP]]: # Supposed to move the cube
       move.dLoc = [0,1,0]
       print('key pressed, move', own)  
    elif INACTIVE == kb.inputs[dict[KEY_UP]]: # Supposed to stop the cube
            move.dLoc = [0,0,0]
            print('key was released, stop moving',own)
    else: # No inputs pressed
            move.dLoc = [0,0,0]
            print('No key input registered')

     cont.activate(move) # Do it!

Not sure if it’s syntax related but I’ve never been able to get a result if I indent else statements in python.

Figured it out. Using bge.logic.keyboard.inputs[bge.events.UPARROWKEY].active works.
You can map any key you specify, it doesn’t have to be the UPARROWKEY.

1 Like