help, double event.

how can i fix my code so that the event didnt trigger twice.
When i press AKEY once, the output are A A.
When i press SKEY once, the output are S S.


import Blender 
 
def event(evt,val): 
    if evt == Blender.Draw.AKEY: 
        print "A" 
    if evt == Blender.Draw.SKEY: 
        print "S" 
    if evt == Blender.Draw.QKEY: 
        Blender.Draw.Exit() 
         
Blender.Draw.Register(None,event,None)

import Blender 
 
def event(evt,val): 
    if evt == Blender.Draw.AKEY: 
        print "A Down" if val else "A Up" 
    if evt == Blender.Draw.SKEY and val == 0: 
        print "S Up"
    if evt == Blender.Draw.QKEY: 
        Blender.Draw.Exit() 
         
Blender.Draw.Register(None,event,None)

Thanks! it works but i dont really understand how it work.

If val is set (ie. 1), it means that the key is initially pressed down. When val is 0, key is released.

the syntax is new to me.
ok, what i understand now I can write

if evt == Blender.Draw.AKEY:
if val == 1: var = 1 #this will get rid the twice problem

It works fine. But when i try

if evt == Blender.Draw.AKEY:
var = 1 if val else var = 0

it show error.

Dont get caught up on the ternary expressions syntactic sugar.

var = x if y else z

is the same as

if y:
    var = x
else: 
    var = z

but as an expression in which you can not do an assignment in python like you did.

var = 1 if val else <b>var = 0</b>

Thanks foom.

This forum is damn good