I'm not sure what you mean by a 'nested if loop'. The
if statement does not loop, it simply checks a condition and executes the nested code if the condition passes. The code you posted would never work because the
key variable can never be equal to 'A' and 'D' at the same time.
One way to check for consecutive key presses is to save the last key press and compare it with the new one. Here is some sample code that does this. It also check how long has elapsed since the last press to make sure the keys were pressed in a short amount of time.
Code:
import viz
viz.go()
lastKey = None
lastKeyTime = 0.0
def onKeyDown(key):
global lastKey,lastKeyTime
elapsed = viz.tick() - lastKeyTime
if lastKey == 'a' and key == 'd' and elapsed < 0.2:
print 'ad pressed'
lastKey = key
lastKeyTime = viz.tick()
viz.callback(viz.KEYDOWN_EVENT,onKeyDown)