How to recognize pressing certain keys without logic bricks?

I’m fairly new to blender. My teacher wants me to code in the text editor instead of using the more visual form of coding in the logic editor. I want to use an always sensor that connects to a motion-making script, which is connected to a motion actuator. It works fine, except my player moves without me pressing down the W key. My problem is finding the right code to say “If you are pressing down the W key, THEN you walk forward.”

Here’s my code:

import bge
cont = bge.logic.getCurrentController()
own = cont.owner

move = cont.actuators[“Motion”]
pressup = cont.sensors[“Always”]

if bge.events.WKEY: #The problem is on this line
move.dLoc = [0.0, .05, 0.0]
cont.activate(move)

The “bge.events.WKEY” is a code that you use to see if that key is pressed. Try this:


if bge.keyboard.events[bge.events.WKEY] == bge.logic.KX_INPUT_ACTIVE:
  move.dLoc = [0.0, 0.5, 0.0]
  cont.activate(move)