question abut rotation

I have made rotation partially in sterted at blender bge from sensor and python in file rotation1
I would like to made it in phyton code like in file rotation2
I have added fragment of code
It is not my filesrotation2.blend (420 KB)rotation1.blend (411 KB)

eyboard = bge.logic.keyboard.events
W = keyboard[bge.events.WKEY]

if W > 0:

buy it not working
Can you help me with it

Sorry from my bed english

Best
regards

You must add an Actuator to the sensors (select from add sensor list), connect it to the controller and copy the python code. Then it should work.

thanks for answer